--------------------sunkaikees@gmail.com-------------------

autoLayout

第一次使用自动布局,记录下来,或许以后用第三方用不到这个,但是第一次接触VFL语言。

一个按钮,不论横竖屏,都要在屏幕底部。

UIView *bottomV = [[UIView alloc]init];

bottomV.backgroundColor = [UIColor whiteColor];

[bottomV setTranslatesAutoresizingMaskIntoConstraints:NO];

[self.view addSubview:bottomV];

添加按钮,不用Fram,

***设置 [bottomV setTranslatesAutoresizingMaskIntoConstraints:NO];

然后按照VFL语言格式设置,||代表边界,如@“H||”,代表水平边界,@“V:||”代表竖向边界,-代表距离,如@“H:|-30-button”表示button距离水平方向上的左侧保持30像素。

1.字典封装要设置的view,并且健值对保存,在后面的可视化各式语言(VFL)中,用key的值代替view,如下例中的@“buttonV”代替buttonV 。

2.编辑可视化格式语言(字符串)。

3.要设置自动布局的父级试图添加约束。(addconstrains)

NSDictionary *view1 = @{@"bottomV":bottomV};

NSString *VString1 = @"V:[bottomV(50)]|";

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:VString1 options:0 metrics:nil views:view1]];

NSString *HString1 =@"H:|-5-[bottomV]-5-|";

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:HString1 options:0 metrics:nil views:view1]];
posted @ 2019-01-17 19:27  雪天微风吹  阅读(95)  评论(0编辑  收藏  举报