aai*_*aev 18 uitableview swift uitableviewautomaticdimension
是否可以为细胞设定最小高度?我用动态:
tableView.estimatedRowHeight = 83.0
tableView.rowHeight = UITableViewAutomaticDimension
Run Code Online (Sandbox Code Playgroud)
但是当我news title label text在一行时,我需要为细胞设置最小高度.
Hyt*_*tek 52
您是否尝试在自定义UITableViewCell视图中创建约束height >= 60.0?
得到它了.使其工作如下.
将视图拖放到UITableViewCell顶部,并将约束前导,尾随,顶部和底部设置为0.将高度约束设置为> = ExpectedMinimumSize.
在heightForRowAtIndexPath Delegate方法中:
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
Run Code Online (Sandbox Code Playgroud)
在ViewDidLoad中:
self.tableView.estimatedRowHeight = 60; // required value.
Run Code Online (Sandbox Code Playgroud)
@Hytek回答了一个窍门。为此,您必须给出最小高度的约束。
例如:如果UILabel表单元格中有一个,并且您希望UILabel根据动态内容增加高度。并且您具有如下代码。
tableView.estimatedRowHeight = 83.0
tableView.rowHeight = UITableViewAutomaticDimension
Run Code Online (Sandbox Code Playgroud)
当内容较大时,它将增加标签的高度,但当内容较小时,它将减小。因此,如果您希望标签的高度最小,那么就必须以一种对标签UILabel的方式height >= 30.0来设置高度限制。
这样,您UILabel将不会降低高度30.0。
| 归档时间: |
|
| 查看次数: |
11992 次 |
| 最近记录: |