AutoLayout约束是苹果官方给定得约束信息。对于这个约束和UIView+AutoLayout.h延展的用法类似,不过加上了延展之后,不用写VFL语言
下面先看看以autolayout实现的效果为例我们讲解一下
下面开始上代码以用户名和密码为例,来说说,
UITextField * userNameTextFiled = [[UITextField alloc] init]; userNameTextFiled.borderStyle = UITextBorderStyleRoundedRect; userNameTextFiled.placeholder = @"用户名"; userNameTextFiled.translatesAutoresizingMaskIntoConstraints=NO; [self.view addSubview:userNameTextFiled]; UITextField * userPwdTextFiled = [[UITextField alloc] init]; userPwdTextFiled.borderStyle = UITextBorderStyleRoundedRect; userPwdTextFiled.placeholder = @"密码"; userPwdTextFiled.translatesAutoresizingMaskIntoConstraints=NO; [self.view addSubview:userPwdTextFiled];
在这里有两点必须说明:1:在对控件allo的时候我们一定忘掉设置他得CGRectMake
2:也是重中之重的,不然会导致严重的性能问题,一定要对当前控件的
translatesAutoresizingMaskIntoConstraints的属性设置为NO,不然无法使用。。。
首先看看这两个约束的方法
- (void)addConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be d
iOS在纯代码中使用AutoLayout添加约束
于 2015-11-28 11:31:31 首次发布