1,如何打印 frame
UIView *view = [[UIView alloc]initWithFrame:CGRectZero];
view.backgroundColor = [UIColor yellowColor];
[self.view addSubview:view];
[view mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(10);
make.top.mas_equalTo(10);
make.width.mas_equalTo(100);
make.height.mas_equalTo(20);
}];
[view layoutIfNeeded];
NSLog(@"%f",view.yj_height);
2,UIScrollView 如何 使用 masnory
UIScrollView *scrollView = [[UIScrollView alloc]init];
scrollView.backgroundColor = [UIColor orangeColor];
scrollView.pagingEnabled =YES;
// 添加scrollView添加到父视图,并设置其约束
[self.view addSubview:scrollView];
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.mas_equalTo(10);
make.right.mas_equalTo(-10);
make.height.mas_equalTo(100);
}];
// 设置scrollView的子视图,即过渡视图contentSize,并设置其约束
UIView *contentView = [[UIView alloc]init];
[scrollView addSubview:contentView];
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(scrollView);
make.height.equalTo(scrollView);
}];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor purpleColor];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.bottom.equalTo(scrollView);
make.width.equalTo(scrollView);
make.left.mas_equalTo(0);
}];
UIView *view = [[UIView alloc]initWithFrame:CGRectZero];
view.backgroundColor = [UIColor blueColor];
[scrollView addSubview: view];
[view mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.bottom.equalTo(scrollView);
make.width.equalTo(scrollView);
make.left.equalTo(button.mas_right);
}];
// 设置过渡视图的右距(此设置将影响到scrollView的contentSize)
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(view.mas_right);
}];
3,利用 masonry 使tableview cell 高度自适应文本
1>
// 必须要给cell高度估计值
_table.estimatedRowHeight = 175;
2>
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60;
}
这个方法不要设置
3>在cell 中用masonry设置
UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectZero];
titleLab.text = @"姓名sasaadsasdmmm姓名asaadsasdmm姓名asaadsasdm姓名asaadsasdm姓名asaadsasdm姓名asaadsasdm姓名asaadsasdm姓名asaadsasdm姓名asaadsasdm姓名asaadsasdm姓名asaadsasdm姓名asaadsasd";
titleLab.textColor = UIColorFromRGB(0x4b4b4b);
titleLab.textAlignment = NSTextAlignmentLeft;
titleLab.font = [UIFont systemFontOfSize:15];
[self.contentView addSubview:titleLab];
titleLab.numberOfLines = 0;
_titleLab = titleLab;
CGFloat kPadding = 10;
[_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kPadding);
make.left.mas_equalTo(kPadding);
make.right.mas_equalTo(-kPadding);
make.bottom.mas_equalTo(-kPadding);
}];
注意这样写 不能在layoutSubviews 方法中设置 layout!!!