日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS开发之第三方框架Masonry

發布時間:2025/3/20 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS开发之第三方框架Masonry 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

第三方框架Masonry

該框架可以大大簡化AutoLayout使用過程中對控件添加約束的代碼。 框架地址:https://github.com/SnapKit/Masonry

  • 使用步驟
    • 添加Masonry文件夾的所有源代碼到項目中
    • 添加2個宏、導入主頭文件
    // 只要添加了這個宏,就不用帶mas_前綴 #define MAS_SHORTHAND // 只要添加了這個宏,equalTo就等價于mas_equalTo #define MAS_SHORTHAND_GLOBALS // 這個頭文件一定要放在上面兩個宏的后面 #import "Masonry.h"
  • mas_equalTo和equalTo的區別: 默認情況下,mas_equalTo有自動包裝功能,比如自動將20包裝為@20,equalTo沒有自動包裝功能,如果添加了下面的宏,那么mas_equalTo和equalTo就沒有區別
#define MAS_SHORTHAND_GLOBALS
  • 添加約束的方法
// 這個方法只會添加新的約束[view makeConstraints:^(MASConstraintMaker *make) {}];// 這個方法會將以前的所有約束刪掉,添加新的約束[view remakeConstraints:^(MASConstraintMaker *make) {}];// 這個方法將會覆蓋以前的某些特定的約束[view updateConstraints:^(MASConstraintMaker *make) {}];
  • 約束的類型
1.尺寸:width\height\size 2.邊界:left\leading\right\trailing\top\bottom 3.中心點:center\centerX\centerY 4.邊界:edges
  • eg
// 藍色控件UIView *blueView = [[UIView alloc] init];blueView.backgroundColor = [UIColor blueColor];[self.view addSubview:blueView];// 居中(水平+垂直)// 尺寸是父控件的一半[blueView mas_makeConstraints:^(MASConstraintMaker *make) {make.size.mas_equalTo(self.view).multipliedBy(0.5);make.center.mas_equalTo(self.view);//make.centerX.mas_equalTo(self.view);//make.centerY.mas_equalTo(self.view);}]; // 藍色控件UIView *blueView = [[UIView alloc] init];blueView.backgroundColor = [UIColor blueColor];[self.view addSubview:blueView];// 紅色控件UIView *redView = [[UIView alloc] init];redView.backgroundColor = [UIColor redColor];[self.view addSubview:redView];// 添加約束CGFloat margin = 20;CGFloat height = 50;[blueView makeConstraints:^(MASConstraintMaker *make) {//make就是指前面調用makeConstraints的對象make.left.equalTo(self.view.left).offset(margin);make.right.equalTo(redView.left).offset(-margin);make.bottom.equalTo(self.view.bottom).offset(-margin);make.height.equalTo(height);make.top.equalTo(redView.top);make.bottom.equalTo(redView.bottom);make.width.equalTo(redView.width);}];[redView makeConstraints:^(MASConstraintMaker *make) {make.right.equalTo(self.view.right).offset(-margin);}];

轉載于:https://my.oschina.net/shenhuniurou/blog/633153

總結

以上是生活随笔為你收集整理的iOS开发之第三方框架Masonry的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。