-1
我有兩個標籤,添加約束標籤編程
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 200, 40)];
[label1 setBackgroundColor:[UIColor clearColor]];
[label1 setText:@"label1"];
[[self view] addSubview:label1];
// Create Label
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 200, 40)];
[label2 setBackgroundColor:[UIColor clearColor]];
[label2 setText:@"label2"];
[[self view] addSubview:label2];
我想通過程序生成這兩個標籤之間的空間,但我不確定如何做到這一點。我試過使用一些來自stackoverflow的答案,但他們給了我錯誤。
像這樣的:
NSLayoutConstraint *c1 = [NSLayoutConstraint
constraintWithItem:UIl.label2
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeLeading
multiplier:1.0f
constant:8.0f];
它給出了什麼錯誤?另外我建議使用砌體進行自動佈局。 –