1
//=======================================tabelview cell autolayout===========================
1
//***********************高度自适应cell设置步骤************************
[self setupAutoHeightWithBottomView:_view3 bottomMargin:bottomMargin];
1.1
//***********************高度自适应cell设置步骤************************
// 当你不确定哪个view在自动布局之后会排布在cell最下方的时候可以调用次方法将所有可能在最下方的view都传过去
[self setupAutoHeightWithBottomViewsArray:@[_titleLabel, _imageView] bottomMargin:margin];
2
/ 此步设置用于实现cell的frame缓存,可以让tableview滑动更加流畅 //
[cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
3
// >>>>>>>>>>>>>>>>>>>>> * cell自适应步骤2 * >>>>>>>>>>>>>>>>>>>>>>>>
/* model 为模型实例, keyPath 为 model 的属性名,通过 kvc 统一赋值接口 */
return [self.tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[DemoVC5CellTableViewCell class] contentViewWidth:[self cellContentViewWith]];
4 //获取高度
- (CGFloat)cellContentViewWith
{
CGFloat width = [UIScreen mainScreen].bounds.size.width;
// 适配ios7
if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 8) {
width = [UIScreen mainScreen].bounds.size.height;
}
return width;
}
2
//======================================= 滚动视图 scrollview autolayout======================
1
// scrollview自动contentsize
[scrollView setupAutoContentSizeWithBottomView:self.view3 bottomMargin:20];
3
//======================================= 设置圆角 ======================
// 设置圆角
self.view0.sd_cornerRadiusFromHeightRatio = @(0.5);
// 设置view0的圆角半径为自身高度的0.5倍
self.view1.sd_cornerRadiusFromWidthRatio = @(0.5);
self.view2.sd_cornerRadiusFromWidthRatio = @(0.5);
4
//================================ 设置等宽的views ======================
//TODO: imageview0 imageview1 imageview2 imageview3 类型伟UIimageview
_imageViewsArray = @[imageView0, imageView1, imageView2];
// 设置等宽的子view
self.contentView.sd_equalWidthSubviews = _imageViewsArray;
有时需要更新一些约束的时候 用到
/** 设置Cell的高度自适应,也可用于设置普通view内容高度自适应 */
- (void)setupAutoHeightWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin;
/** 用于设置普通view内容宽度自适应 */
- (void)setupAutoWidthWithRightView:(UIView *)rightView rightMargin:(CGFloat)rightMargin;
/** 设置Cell的高度自适应,也可用于设置普通view内容自适应(应用于当你不确定哪个view在自动布局之后会排布在最下方最为bottomView的时候可以调用次方法将所有可能在最下方的view都传过去) */
- (void)setupAutoHeightWithBottomViewsArray:(NSArray *)bottomViewsArray bottomMargin:(CGFloat)bottomMargin;
/** 更新布局(主动刷新布局,如果你需要设置完布局代码就获得view的frame请调用此方法) */
- (void)updateLayout;
/** 更新cell内部的控件的布局(cell内部控件专属的更新约束方法,如果启用了cell frame缓存则会自动清除缓存再更新约束) */
- (void)updateLayoutWithCellContentView:(UIView *)cellContentView;
/** 清空高度自适应设置 */
- (void)clearAutoHeigtSettings;
/** 清空宽度自适应设置 */
- (void)clearAutoWidthSettings;