第一次使用自動(dòng)布局,記錄下來(lái),或許以后用第三方用不到這個(gè),但是第一次接觸VFL語(yǔ)言。
一個(gè)按鈕,不論橫豎屏,都要在屏幕底部。
UIView *bottomV = [[UIView alloc]init];
bottomV.backgroundColor = [UIColor whiteColor];
[bottomV setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:bottomV];
添加按鈕,不用Fram,
***設(shè)置 [bottomV setTranslatesAutoresizingMaskIntoConstraints:NO];
然后按照VFL語(yǔ)言格式設(shè)置,||代表邊界,如@“H||”,代表水平邊界,@“V:||”代表豎向邊界,-代表距離,如@“H:|-30-button”表示button距離水平方向上的左側(cè)保持30像素。
1.字典封裝要設(shè)置的view,并且健值對(duì)保存,在后面的可視化各式語(yǔ)言(VFL)中,用key的值代替view,如下例中的@“buttonV”代替buttonV 。
2.編輯可視化格式語(yǔ)言(字符串)。
3.要設(shè)置自動(dòng)布局的父級(jí)試圖添加約束。(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]];