用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];
解决方案 »
- 请问查iPhone程序的内存泄露怎么查?
- 【iphone扫盲贴】 认识iPhone
- ios 使用ShareSDK实现分享时出错
- tableView cellforrowatindexpath 方法不掉用
- 华为开发者联盟推出的华为推送有什么优势啊?
- 开发者选项有什么用?
- 如何实现在一个viewcontroller上加载另一个viewcontroller
- 苹果企业证书打包的app,有些苹果的手机下载提示:无法下载应用程序. 个别苹果手机还能安装成功. ?
- 升级到xcode 8.0 后的问题 忘大牛帮帮忙
- 求iOS 摄影+滤镜app的教程~
- 程序在屏幕解锁后就会崩溃,一般是什么问题呢?
- iOS 滑过的图片怎么取消下载?
@zhangao0086 要的是置底,(用NSLayoutAttributeCenterX或NSLayoutAttributeCenterY不行?)这个不是居中吗?