NSLayoutConstraint的简单应用
2015-12-22 00:41
573 查看
UIView *topView = [[UIView alloc] init]; topView.backgroundColor = [UIColor redColor]; [self.view addSubview:topView]; topView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addConstraints:@[ [NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10], [NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-10], [NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:100], [NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20] ]];
topView在父视图的左边间距10,下边间距-10,宽度为100,高度为20的实现代码
相关文章推荐
- Contains Duplicate II
- Daily Scrum NO.10
- C++迭代器失效http://blog.csdn.net/vipvipvip/article/details/6295973
- Daily Scrumming* 2015.12.21(Day 13)
- Yocto tips (14): Yocto中编译链的配置变更(tuning)
- 认识retain copy assign strong weak 的区别
- LeetCode 11 - Container With Most Water
- 使用Commons Email发送邮件
- 让机器人模块 PyAIML 平滑处理中文
- ACboy needs your help again!(杭电1702)(栈和队列的基础应用)
- 多线程wait-notify;notifyall.sleep
- SHU1952 Odd Pairs(维护前缀和)
- 派生类到基类的转换 和基类到派生类的转换 http://blog.csdn.net/wyyzsl212328/article/details/8263959
- 博弈算法实现简单五子棋
- MHA自动Failover过程解析(updated)(转)
- postfix mail command not found
- “Operation could not be completed. (SKErrorDomain error 0.)”
- 服务器TIME_WAIT和CLOSE_WAIT详解和解决办法
- 解决svn Authorization failed错误【SVN权限问题】
- Daily Scrum - 12/15-21