国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS 用XIB約束后,用代碼修改約束

2019-11-08 00:17:41
字體:
來源:轉載
供稿:網友

當使用xib,并使用了AutoLayout之后,當需要適配機型時,或者手動更改視圖的frame的時候,就需要修改約束啦.其實很簡單的. 1.首先從xib中吧改變的約束拖到view上或者ViewController上 @PRoperty (weak, nonatomic) IBOutlet NSLayoutConstraint *topLayout;

機型封裝到單例中 全局都可以使用

+ (UIScreenSizeType)currentScreenSizeType{ if (CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size)) { return UIScreenSizeType_640x960; } else if(CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)){ return UIScreenSizeType_640x1136; }else if(CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size)){ return UIScreenSizeType_750x1334; }else if(CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)){ return UIScreenSizeType_1242x2208; } return UIScreenSizeType_000x000;} if([UIScreen currentScreenSizeType] == UIScreenSizeType_640x960){ _topLayout.constant = 40; }else if([UIScreen currentScreenSizeType] == UIScreenSizeType_640x1136){ _topLayout.constant = 40; }else if([UIScreen currentScreenSizeType] == UIScreenSizeType_750x1334){ _topLayout.constant = 40; }else if([UIScreen currentScreenSizeType] == UIScreenSizeType_1242x2208){ _topLayout.constant = 40; }

2.還可以為控件自定義一個約束

NSLayoutConstraint *myConstraint =[NSLayoutConstraint constraintWithItem:iSinaButton //子試圖 attribute:NSLayoutAttributeCenterX //子試圖的約束屬性 relatedBy:NSLayoutRelationEqual //屬性間的關系 toItem:self.view//相對于父試圖 attribute:NSLayoutAttributeCenterX//父試圖的約束屬性 multiplier:1.0 constant:0.0];// 固定距離[self.view addConstraint: myConstraint];//為iSinaButton重新添加一個約束
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海林市| 重庆市| 元朗区| 大连市| 治多县| 屯留县| 田东县| 柏乡县| 泗水县| 共和县| 翼城县| 樟树市| 梁山县| 河曲县| 抚顺市| 徐闻县| 睢宁县| 城口县| 丽水市| 崇仁县| 罗城| 仪陇县| 松原市| 高台县| 肇源县| 五指山市| 宁武县| 宜兰市| 龙岩市| 福清市| 金堂县| 延庆县| 汉沽区| 出国| 临沧市| 东平县| 淮阳县| 铜川市| 林西县| 都安| 盐亭县|