|
2 | 2 | 致力于做最简单易用的Autolayout库。The most easy way for autolayout. |
3 | 3 |
|
4 | 4 | # 摒弃复杂累赘的约束,利用运行时Runtime在合适的时机布局视图。 |
| 5 | + |
| 6 | + |
| 7 | +# ☆新增:label文字自适应 + cell高度自适应☆ |
| 8 | + |
| 9 | + >> UILabel文字自适应: |
| 10 | + // autoHeightRatio() 传0则根据文字自动计算高度(传大于0的值则根据此数值设置高度和宽度的比值) |
| 11 | + _label.sd_layout.autoHeightRatio(0); |
| 12 | + |
| 13 | + >> Cellg高度自适应: |
| 14 | + // cell布局设置好之后调用此方法就可以实现高度自适应(注意:如果用高度自适应则不要再以cell的底边为参照去布局其子view) |
| 15 | + [self setupAutoHeightWithBottomView:_view4 bottomMargin:10]; |
| 16 | + |
| 17 | + 设置tableview数据源和代理 |
| 18 | + |
| 19 | + - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
| 20 | + { |
| 21 | + // >>>>>>>>>>>>>>>>>>>>> * cell自适应步骤1 * >>>>>>>>>>>>>>>>>>>>>>>> |
| 22 | + [self.tableView startAutoCellHeightWithCellClass:“cell类名” contentViewWidth:“contentview宽度”]; |
| 23 | + |
| 24 | + return _rowCount; |
| 25 | + } |
| 26 | + |
| 27 | + - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath |
| 28 | + { |
| 29 | + // >>>>>>>>>>>>>>>>>>>>> * cell自适应步骤2 * >>>>>>>>>>>>>>>>>>>>>>>> |
| 30 | + return [self.tableView cellHeightForIndexPath:indexPath model:“model” keyPath:@"model属性名"]; |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | +# ****************普通view的自动布局*************** |
| 35 | + |
5 | 36 | # 0.用法示例 |
6 | 37 | /* 用法一 */ |
7 | 38 | _view.sd_layout |
|
13 | 44 | /* 用法二 (一行代码搞定,其实用法一也是一行代码) */ |
14 | 45 | _view.sd_layout.leftSpaceToView(self.view, 10).topSpaceToView(self.view,80).heightIs(130).widthRatioToView(self.view, 0.4); |
15 | 46 |
|
16 | | -# ☆新增:label文字自适应 + cell高度自适应☆ |
17 | | - // autoHeightRatio() 传0则根据文字自动计算高度(传大于0的值则根据此数值设置高度和宽度的比值) |
18 | | - _label.sd_layout.autoHeightRatio(0); |
19 | | - |
20 | | - // cell布局设置好之后调用此方法就可以实现高度自适应(注意:如果用高度自适应则不要再以cell的底边为参照去布局其子view) |
21 | | - [self setupAutoHeightWithBottomView:_view4 bottomMargin:10]; |
22 | | - |
23 | 47 | ******************************************************************************* |
24 | 48 | |
25 | 49 | 注意:先把需要自动布局的view加入父view然后在进行自动布局,例: |
|
0 commit comments