tableview和cell高度自适应
来源:互联网 发布:淘宝扬琴 编辑:程序博客网 时间:2024/06/05 23:00
普通(简化)版【推荐使用】:tableview 高度自适应设置只需要2步
1. >> 设置cell高度自适应:// cell布局设置好之后调用此方法就可以实现高度自适应(注意:如果用高度自适应则不要再以cell的底边为参照去布局其子view)[cell setupAutoHeightWithBottomView:_view4 bottomMargin:10];2. >> 获取自动计算出的cell高度- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ id model = self.modelsArray[indexPath.row]; // 获取cell高度 return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[DemoVC9Cell class] contentViewWidth:cellContentViewWith];
}
升级版(适应于cell条数少于100的tableview):tableview 高度自适应设置只需要2步
1. >> 设置cell高度自适应:// cell布局设置好之后调用此方法就可以实现高度自适应(注意:如果用高度自适应则不要再以cell的底边为参照去布局其子view)[cell setupAutoHeightWithBottomView:_view4 bottomMargin:10];2. >> 获取自动计算出的cell高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{// 获取cell高度return [self cellHeightForIndexPath:indexPath cellContentViewWidth:[UIScreen mainScreen].bounds.size.width];}
普通view的自动布局:
用法示例
/* 用法一 */_view.sd_layout.leftSpaceToView(self.view, 10).topSpaceToView(self.view, 80).heightIs(130).widthRatioToView(self.view, 0.4); /* 用法二 (一行代码搞定,其实用法一也是一行代码) */_view.sd_layout.leftSpaceToView(self.view, 10).topSpaceToView(self.view,80).heightIs(130).widthRatioToView(self.view, 0.4);>> UILabel文字自适应:// autoHeightRatio() 传0则根据文字自动计算高度(传大于0的值则根据此数值设置高度和宽度的比值)_label.sd_layout.autoHeightRatio(0);******************************************************************************* 注意:先把需要自动布局的view加入父view然后在进行自动布局,例: UIView *view0 = [UIView new]; UIView *view1 = [UIView new]; [self.view addSubview:view0]; [self.view addSubview:view1]; view0.sd_layout .leftSpaceToView(self.view, 10) .topSpaceToView(self.view, 80) .heightIs(100) .widthRatioToView(self.view, 0.4); view1.sd_layout .leftSpaceToView(view0, 10) .topEqualToView(view0) .heightRatioToView(view0, 1) .rightSpaceToView(self.view, 10);*******************************************************************************
自动布局用法简析
1.1 > leftSpaceToView(self.view, 10)
方法名中带有“SpaceToView”的方法表示到某个参照view的间距,需要传递2个参数:(UIView)参照view 和 (CGFloat)间距数值
1.2 > widthRatioToView(self.view, 1)
方法名中带有“RatioToView”的方法表示view的宽度或者高度等属性相对于参照view的对应属性值的比例,需要传递2个参数:(UIView)参照view 和 (CGFloat)倍数
1.3 > topEqualToView(view)
方法名中带有“EqualToView”的方法表示view的某一属性等于参照view的对应的属性值,需要传递1个参数:(UIView)参照view
1.4 > widthIs(100)
方法名中带有“Is”的方法表示view的某一属性值等于参数数值,需要传递1个参数:(CGFloat)数值
0 0
- tableview和cell高度自适应
- tableView 的cell自适应高度
- swift tableview cell自适应高度
- Tableview中cell的自适应高度
- tableView自适应cell的高度,提高性能
- iOS8 tableView的Cell高度自适应开发
- 使用storyboard tableView的cell自适应高度
- [iOS]TableView的Cell高度自适应
- cell和lable自适应高度
- iOS自动布局实现Cell和Tableview高度自适应(SDAutoLayout)
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- ios TableView的Cell高度自适应,UILabel自动换行适应
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- AndroidStudio-加载so文件与jar包(可能是最完美的解决方法)
- android_第三方插件的使用
- 协方差矩阵 阵列处理基础
- 。。。。
- [开源] Android 代码高亮显示控件
- tableview和cell高度自适应
- 基于jquery.qrcode.min.js的二维码实现
- 3717: [PA2014]Pakowanie
- 对C++多文件程序的总结及例程
- 面试题test
- andrid studio 使用攻略
- 集合和流的综合运用
- Android Layout
- [译]Go Slices: usage and internals