美文网首页
iOS UIViewController Masonry适配安

iOS UIViewController Masonry适配安

作者: writeSpace | 来源:发表于2020-12-15 11:33 被阅读0次

给控制器添加分类

@interface UIViewController (YQ)

- (MASViewAttribute *)yq_safe_top;
- (MASViewAttribute *)yq_safe_bottom;
@end

#import "UIViewController+YQ.h"

@implementation UIViewController (YQ)



- (MASViewAttribute *)yq_safe_top {
    if (@available(iOS 11.0, *)) {
        return self.view.mas_safeAreaLayoutGuideTop;
    } else {
        // Fallback on earlier versions
        return self.mas_topLayoutGuideBottom;
    }
}

- (MASViewAttribute *)yq_safe_bottom {
    if (@available(iOS 11.0, *)) {
        return self.view.mas_safeAreaLayoutGuideBottom;
    } else {
        // Fallback on earlier versions
        return self.mas_bottomLayoutGuideTop;
    }
}

@end

调用

以tableView为例

[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(@0);
            make.width.mas_equalTo(tableViewH);
            make.top.equalTo(self.yq_safe_top);
            make.bottom.equalTo(self.yq_safe_bottom);
        }];

简单易用

相关文章

网友评论

      本文标题:iOS UIViewController Masonry适配安

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