美文网首页
iOS 获取安全边距

iOS 获取安全边距

作者: _菩提本无树_ | 来源:发表于2023-11-23 16:03 被阅读0次
    // 导航栏高度
    #define kNavBarHeight \
    ({\
        CGFloat height = 0.0;\
        if (@available(iOS 11.0, *)) {\
            UIEdgeInsets insets = [UIApplication sharedApplication].delegate.window.safeAreaInsets;\
            height = insets.top > 0 ? 44.0 + insets.top : 44.0;\
        } else {\
            height = 64.0;\
        }\
        height;\
    })
    
    // 状态栏高度
    #define kStatusBarHeight \
    ({\
        CGFloat height = 0.0;\
        if (@available(iOS 11.0, *)) {\
            UIEdgeInsets insets = [UIApplication sharedApplication].delegate.window.safeAreaInsets;\
            height = insets.top;\
        } else {\
            height = 20.0;\
        }\
        height;\
    })
    
    // 标签栏高度
    #define kTabBarHeight \
    ({\
        CGFloat height = 0.0;\
        if (@available(iOS 11.0, *)) {\
            UIEdgeInsets insets = [UIApplication sharedApplication].delegate.window.safeAreaInsets;\
            height = insets.bottom > 0 ? 49.0 + insets.bottom : 49.0;\
        } else {\
            height = 49.0;\
        }\
        height;\
    })
    
    // 安全区域底部高度
    #define kSafeAreaBottomHeight \
    ({\
        CGFloat height = 0.0;\
        if (@available(iOS 11.0, *)) {\
            UIEdgeInsets insets = [UIApplication sharedApplication].delegate.window.safeAreaInsets;\
            height = insets.bottom;\
        }\
        height;\
    })
    
    

    相关文章

      网友评论

          本文标题:iOS 获取安全边距

          本文链接:https://www.haomeiwen.com/subject/slyvwdtx.html