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

首頁 > 學院 > 開發設計 > 正文

VFL

2019-11-09 15:05:23
字體:
來源:轉載
供稿:網友

原文鏈接:http://www.cnblogs.com/chars/p/5146607.html

VFL(Visual Format Language),“可視化格式語言”。

VFL是蘋果公司為了簡化autolayout的編碼而推出的抽象語言。

語法說明

復制代碼
H:[cancelButton(72)]-12-[acceptButton(50)]cancelButton寬72,acceptButton寬50,它們之間間距12 H:[wideView(>=60@700)]wideView寬度大于等于60point,該約束條件優先級為700(優先級最大值為1000,優先級越高的約束條件越先被滿足)  V:[redBox][yellowBox(==redBox)]垂直方向上,先有一個redBox,其下方緊接一個高度等于redBox高度的yellowBox  H:|-10-[Find]-[FindNext]-[FindField(>=20)]-|水平方向上,Find距離父view左邊緣間隔10,之后是FindNext距離Find間隔默認寬度;再之后是寬度不小于20的FindField,它和FindNext以及父view右邊邊緣的間距都是默認寬度。(豎線“|”表示superview的邊緣)。復制代碼

使用方法

復制代碼
使用VFL來創建約束數組+(NSArray *)constraintsWithVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views;  format:VFL語句opts:約束類型metrics:VFL語句中用到的具體數值views:VFL語句中用到的控件  創建一個字典(內部包含VFL語句中用到的控件)的快捷宏定義NSDictionaryOfVariableBindings(...)復制代碼

實例展示

效果圖如下:

             

實現代碼:

復制代碼
-(void)horizontalLayout{    //1.添加兩個控件    UIView *blueView = [[UIView alloc] init];    blueView.backgroundColor = [UIColor blueColor];        blueView.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:blueView];        UIView *redView = [[UIView alloc] init];    redView.backgroundColor = [UIColor redColor];    redView.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:redView];        //2.添加約束    //2.1水平方向的約束    NSString *hVFL = @"H:|-30-[blueView]-30-[redView(==blueView)]-30-|";    NSArray *hCons = [NSLayoutConstraint constraintsWithVisualFormat:hVFL options:NSLayoutFormatAlignAllBottom | NSLayoutFormatAlignAllTop metrics:nil views:@{@"blueView":blueView, @"redView":redView}];    [self.view addConstraints:hCons];        //2.2垂直方向的約束    NSString *vVFL = @"V:[blueView(50)]-30-|";    NSArray *vCons = [NSLayoutConstraint constraintsWithVisualFormat:vVFL options:0 metrics:nil views:@{@"blueView":blueView}];    [self.view addConstraints:vCons];}-(void)verticalLayout{    //1.添加兩個控件    UIView *blueView = [[UIView alloc] init];    blueView.backgroundColor = [UIColor blueColor];    blueView.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:blueView];    UIView *redView = [[UIView alloc] init];    redView.backgroundColor = [UIColor redColor];    redView.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:redView];    //2.添加約束    //2.1水平方向的約束    NSString *hVFL = @"H:|-30-[blueView]-30-|";    NSArray *hCons = [NSLayoutConstraint constraintsWithVisualFormat:hVFL options:0 metrics:nil views:@{@"blueView":blueView}];    [self.view addConstraints:hCons];    //2.2垂直方向的約束    NSString *vVFL = @"V:|-30-[blueView(50)]-30-[redView(==blueView)]";    NSArray *vCons = [NSLayoutConstraint constraintsWithVisualFormat:vVFL options:NSLayoutFormatAlignAllRight metrics:nil views:@{@"blueView":blueView, @"redView":redView}];    [self.view addConstraints:vCons];    NSLayoutConstraint *redLeftCon = [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];    [self.view addConstraint:redLeftCon];}復制代碼

小結

最后對格式的字符串作一個總結介紹:

功能表達式
水平方向H:
垂直方向V:
Views[view]
SuperView|
關系>=,==,<=
空間,間隙-
優先級@value

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南召县| 宜兰县| 博罗县| 蒙山县| 南通市| 临邑县| 隆回县| 六安市| 太和县| 吴堡县| 南昌县| 东安县| 富平县| 大荔县| 兴义市| 石阡县| 尚义县| 石渠县| 电白县| 西青区| 墨脱县| 稻城县| 鱼台县| 泾源县| 余干县| 罗城| 台安县| 三江| 霸州市| 岳普湖县| 石嘴山市| 濮阳县| 大理市| 高安市| 乐东| 林口县| 孙吴县| 临泽县| 广安市| 治多县| 六盘水市|