swift 约束 - SnapKit - 适配iPhoneX 安全区

 1 这里tableview 是从最顶上的安全区适配的, nextBtn是最下边从安全区设置的,如果是在中间的view还是原来的写法,看2
 2     1.   tableview.snp.makeConstraints { (make) in
 3             if #available(iOS 11.0, *) {
 4                 make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top)
 5             } else {
 6                 make.top.equalTo(self.topLayoutGuide.snp.top)
 7             }
 8 
 9             make.centerY.equalTo(view)
10             make.width.equalTo(view)
11             make.bottom.equalTo(view).inset(-60)
12         }
13         
14         view.addSubview(nextBtn)
15         nextBtn.snp.makeConstraints { (make) in
16             
17             make.left.equalTo(tableview)
18             make.right.equalTo(tableview)
19             if #available(iOS 11.0, *) {
20                 make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom)
21             } else {
22                 make.bottom.equalTo(self.bottomLayoutGuide.snp.bottom)
23             }
24             make.height.equalTo(60)
25         }
26 
27 
28 2. 非安全区写法还和原来一样
29 
30         titleLabel.snp.makeConstraints { (make) in
34             make.left.equalTo(view).offset(24)
38             make.top.equalTo(view).offset(24)
40 }


详情使用链接 :

SnapKit的详细使用介绍 :https://www.jianshu.com/p/2bad53a2a180

  

猜你喜欢

转载自www.cnblogs.com/qingzZ/p/9242928.html