用NSAutoLayout 纯代码自动布局。在UIScrollView上底部添加视图。却显示在最上面。咋解?
UIScrollView *baseScrollView = [[UIScrollView alloc] init];
[baseScrollView setBackgroundColor:[UIColor whiteColor]];
baseScrollView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:baseScrollView];
[baseScrollView release];
NSLayoutConstraint *baseScrollViewConstaints1 = [NSLayoutConstraint constraintWithItem:baseScrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
NSLayoutConstraint *baseScrollViewConstaints2 = [NSLayoutConstraint constraintWithItem:baseScrollView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0];
[self.view addConstraint:baseScrollViewConstaints1];
[self.view addConstraint:baseScrollViewConstaints2];
UILabel *label1 = [[UILabel alloc] init];
[label1 setText:@"?:|}{'"];
label1.translatesAutoresizingMaskIntoConstraints = NO;
[label1 setTextColor:[UIColor redColor]];
[label1 setBackgroundColor:[UIColor whiteColor]];
[baseScrollView addSubview:label1];
[label1 release];
NSDictionary *viewDict = NSDictionaryOfVariableBindings(label1);
NSArray *viewConstraints1 = [NSLayoutConstraint constraintsWithVisualFormat:@"|-[label1]-|" options:0 metrics:nil views:viewDict];
NSArray *viewConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[label1]-|" options:0 metrics:nil views:viewDict];
[baseScrollView addConstraints:viewConstraints1];
[baseScrollView addConstraints:viewConstraints2];
UIScrollView *baseScrollView = [[UIScrollView alloc] init];
[baseScrollView setBackgroundColor:[UIColor whiteColor]];
baseScrollView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:baseScrollView];
[baseScrollView release];
NSLayoutConstraint *baseScrollViewConstaints1 = [NSLayoutConstraint constraintWithItem:baseScrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
NSLayoutConstraint *baseScrollViewConstaints2 = [NSLayoutConstraint constraintWithItem:baseScrollView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0];
[self.view addConstraint:baseScrollViewConstaints1];
[self.view addConstraint:baseScrollViewConstaints2];
UILabel *label1 = [[UILabel alloc] init];
[label1 setText:@"?:|}{'"];
label1.translatesAutoresizingMaskIntoConstraints = NO;
[label1 setTextColor:[UIColor redColor]];
[label1 setBackgroundColor:[UIColor whiteColor]];
[baseScrollView addSubview:label1];
[label1 release];
NSDictionary *viewDict = NSDictionaryOfVariableBindings(label1);
NSArray *viewConstraints1 = [NSLayoutConstraint constraintsWithVisualFormat:@"|-[label1]-|" options:0 metrics:nil views:viewDict];
NSArray *viewConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[label1]-|" options:0 metrics:nil views:viewDict];
[baseScrollView addConstraints:viewConstraints1];
[baseScrollView addConstraints:viewConstraints2];
@zhangao0086 要的是置底,(用NSLayoutAttributeCenterX或NSLayoutAttributeCenterY不行?)这个不是居中吗?