02-UITableview(1)

0602AutoLayout表格


1. 04-vfl01


用代码写约束一定要加上下面这句话

blueView.translatesAutoresizingMaskIntoConstraints = NO;

其作用是告诉xcode不要再自动添加约束以免和手动添加的约束冲突,注意,如果用故事板拖线添加约束这句话是自动执行的,不需要我们管理

2. 05-vfl02


代码手写原生约束小结:
有两种,一种是一条一条添加,一种是批量添加(VFL),
一条一条:

UIView *blueView = [[UIView alloc] init];
blueView.backgroundColor = [UIColor blueColor];
// 不要将AutoresizingMask转为Autolayout的约束
blueView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:blueView];
// 添加高度约束:40 
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:blueView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:40];
[blueView addConstraint:heightConstraint];

批量(VFL):

UIView *blueView = [[UIView alloc] init];
blueView.backgroundColor = [UIColor blueColor];
// 不要将AutoresizingMask转为Autolayout的约束
blueView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:blueView];
// 间距
NSNumber *margin = @20;
// 添加水平方向的约束
NSString *vfl = @"H:|-margin-[blueView]-margin-[redView(==blueView)]-margin-|";
NSDictionary *views = NSDictionaryOfVariableBindings(blueView, redView);
NSDictionary *mertrics = NSDictionaryOfVariableBindings(margin);
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:vfl options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom metrics:mertrics views:views];
[self.view addConstraints:constraints];

注意:VFL有两种情况下使用无效,一是一个方向上有并列的多个控件,这时候只能写一个控件,其余控件要用第一种方法一个一个的把该方向的约束添加进去;还有种情况是VFL不能添加长宽为比例的情况,这时候也只能用第一种方法。

3. 05-vfl02


一个快捷创建字典的宏

NSDictionary *dict = NSDictionaryOfVariableBindings(@"aaa",@"bbb",@"ccc");

4. 12-uitableview02-多组数据


cell的detail文字在cell的style为subtitle时才会显示(value1也可以,会把detail显示到右边),default不会

5. 14-uitableview02-单组数据

  • 组标题在tableview的style为plain时才会悬停,group不会
  • tableview创建后默认行高44,与导航栏一样

6. 14-uitableview02-单组数据


把字典键值对转自定义的模型的API:

[hero setValuesForKeysWithDictionary:dict];

你可能感兴趣的:(02-UITableview(1))