【发布时间】:2023-03-09 15:40:02
【问题描述】:
自定义 UITableViewCell 中有一个 view1(UIView),我希望在 AutoLayout 之后绘制新尺寸的 view1(UIView) 来绘制边框
UITableViewCell 的内容是动态的,因此我使用了 UITableViewAutomaticDimension 来自动调整大小
我也使用以下方法,但我得到了原始尺寸。展开后我无法获得 view1(UIView) 的新尺寸
[self.tblView1 setNeedsLayout];
[self.tblView1 layoutIfNeeded];
[cell.view1 setNeedsLayout];
[cell.view1 layoutIfNeeded];
CALayer *rightBorder = [CALayer layer];
rightBorder.backgroundColor = [[UIColor redColor] CGColor];
rightBorder.frame = CGRectMake(cell.view1.frame.size.width-1, 0, 1, cell.view1.frame.size.height);
[cell.view1.layer addSublayer:rightBorder];
rightBorder 是绘制的,但根据 view1 的(UIView)原始尺寸,即 Width = 394 Height = 322 不根据 view1 的(UIView)新尺寸后的布局尺寸,即 Width = 394 Height = 422
【问题讨论】:
-
你设置了tableView的
estimatedRowHeight属性了吗? -
@Rishab 当然是的,兄弟 self.tbl.estimatedRowHeight = 323; self.tbl.rowHeight = UITableViewAutomaticDimension;没有上面的代码,我无法得到动态单元格大小的结果
-
你是在
initWithFrame:里面写代码还是自定义方法? -
@Rishab 你在下面的代码中使用 abt 是的,我写了 rightBorder.frame = CGRectMake(cell.view1.frame.size.width-1, 0, 1, cell.view1.frame.size.height );如果不是,那么我应该写什么 initWithFrame
标签: ios objective-c uitableview autolayout ios-autolayout