1.lable自适应高度
UILabel *lable = [[UILabel alloc]init];
lable.backgroundColor = [UIColor whiteColor];
lable.text = @"是点击四个挤到佛教给对方加工件都构建偶家二极管日接口了大杀四方莱克斯顿,是发动机盖我几十个及地方机构我奇偶加尔文公祭日公积金都是类控件的房价高的";
lable.font = [UIFont systemFontOfSize:20];
lable.textColor = [UIColor redColor];
lable.numberOfLines = 0;
[scrollView addSubview:lable];
[lable mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(greenView);
make.top.equalTo(greenView.mas_bottom).offset(12);
}];
2.UIScrollView的contenSize自适应
UIScrollView *scrollView = [[UIScrollView alloc]init];
scrollView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:scrollView];
UIView *contentView= [[UIView alloc]init];
contentView.backgroundColor = [UIColor orangeColor];
[scrollView addSubview:contentView];
UIView *redView = [[UIView alloc]init];
redView.backgroundColor = [UIColor redColor];
[scrollView addSubview: redView];
UIView *yeallowView = [[UIView alloc]init];
yeallowView.backgroundColor = [UIColor yellowColor];
[scrollView addSubview:yeallowView];
UIView *greenView = [[UIView alloc]init];
greenView.backgroundColor = [UIColor greenColor];
[scrollView addSubview:greenView];
UIView *lightView = [[UIView alloc]init];
lightView.backgroundColor = [UIColor lightGrayColor];
[scrollView addSubview:lightView];
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
CGFloat padding = 25.0;
[greenView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.equalTo(scrollView).offset(padding);
make.size.mas_equalTo(CGSizeMake(250, 250));
}];
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(greenView.mas_bottom).offset(padding);
make.left.equalTo(greenView.mas_right).offset(padding);
make.size.equalTo(greenView);
make.right.equalTo(scrollView).offset(-padding);
}];
[yeallowView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(scrollView).offset(padding);
make.top.equalTo(redView.mas_bottom).offset(padding);
make.size.equalTo(greenView);
make.bottom.equalTo(scrollView).offset(-padding);
}];
3.TableViewCell的自适应
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStylePlain];
[tableView registerClass:[TestCell class] forCellReuseIdentifier:@"cell"];
tableView.delegate = self;
tableView.dataSource =self;
tableView.rowHeight = UITableViewAutomaticDimension;
[self.view addSubview:tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 20;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
TestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
return cell;
}
自定义cell里面的主要代码
UILabel *titleLb = [[UILabel alloc]init];
titleLb.textColor =[UIColor redColor];
titleLb.numberOfLines = 0;
titleLb.text = @"是都加哦我接发动is加都加个介绍的 就放商店防静电房管局死哦的几个我偶家死哦接我 我加个我我就都给我就是地方官基数低计算机那是块几点放圣诞节梵蒂冈我我就诶关键人物 ";
[self.contentView addSubview:titleLb];
[titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(20);
make.right.equalTo(self.contentView).offset(30);
make.top.equalTo(self.contentView).offset(20);
make.bottom.equalTo(self.contentView).offset(-20);
}];