IOS之Masonry约束的使用
IOS之Masonry約束的使用
Masonry是做約束的,類似蘋果開發的約束,做屏幕的適配,有xib開發,純代碼開發,storyboard約束等其他第三方框架。
pod 加入
pod 'Masonry', '~> 1.1.0'懶得加版本直接寫
pod 'Masonry'pod install安裝的時候,默認給你安裝最新版本。截止我發稿的時候,2021年11月份,版本更新到1.1.0,我用軟件只用最新版本。舊版本不用
需要用的地方包含一下頭文件#import <Masonry/Masonry.h>,懶得重復包含,直接在pch文件包含一次即可。
//6.布局控制器的view[newVc.view mas_makeConstraints:^(MASConstraintMaker *make) {make.top.right.bottom.equalTo(self.view);make.left.equalTo(self.dockView.mas_right);}];距離上右下和當前的view相等。
距離左邊和??繖诘挠疫叺南嗟?。
類似的,可以慢慢積累。
[citySearchResultController.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.mas_top);
//如果約束的邊前后相等,那么后面的可以不寫
// make.top.equalTo(self.view);
// make.left.right.bottom.equalTo(self.view);
// make.top.equalTo(self.tableView).offset(15);
make.edges.equalTo(self.tableView);
二. 對于某一自定義view如何約束到左下角呢:
解決方案如下:有2種方法
pathMenu當作是View的子類
案例3:
[topView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.top.right.offset(0);make.height.offset(115);}];//距離左上右 為 0 高度 115UIView *functionListView = [[UIView alloc]init];functionListView.backgroundColor = UIColor.purpleColor;[self.view addSubview:functionListView];[functionListView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.right.bottom.offset(0);make.top.equalTo(topView.mas_bottom).offset(0);}]; //距離 下 左 右 為 0 距離 topView 的底部 為0總結
以上是生活随笔為你收集整理的IOS之Masonry约束的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你的代码(软件)安全吗?【信息图】
- 下一篇: IOS之通知NSNotification