我们如何在uitableview单元格中设置标签约束?
我想在tableview单元格中设置一个Label Constraints。 当我设置标签约束并在设备上运行时,自动布局不适用于iPhone 5,6和iPhone 7以外的其他设备。我们如何在uitableview单元格中设置标签约束?
如何设置自动布局约束拿到布局的所有设备工作正常?
谢谢!
试一试 -
拖动一个标签进入细胞。 假设你想要从标签的每一边有10个像素的边距。为所有(顶部,底部,前导,尾部)设置一个常数10,然后单击添加4约束。如下面的图像现在
,如果你有唯一的问题与标签的宽度,然后执行以下操作 -
在viewWillAppear
方法
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = 50.0;
然后用下面的方法 -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
return UITableViewAutomaticDimension;
}
而你亲现在应该解决瑕疵。
您必须为单元格提供估计的行高或将其设置为自动。
例子: -
tableView.estimatedRowHeight = 120.0
tableView.rowHeight = UITableViewAutomaticDimension
或通过这样的: -
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return 240
}
非高度问题,当应用程序在小设备上运行时,标签宽度未根据屏幕设置 –
您必须为各个视图提供tableView约束。 –
您需要设置以下PARAMS
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = 140.0; //some values according to the your requirement
你的意思是不工作?提供一些经过验证的代码和结果 –
对所有约束(前导,尾随,顶部,底部)使用比例值 –
当应用程序在小型设备上运行时,根据屏幕设置uilabel宽度。 –