SDautolayout 常用方法

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;

更新中。。。。。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值