给控制器添加分类
@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);
}];
简单易用
网友评论