正确设置UITableViewCell的高度,使UITableViewCell子类有正确的边界
本文关键字:UITableViewCell 边界 子类 高度 设置 | 更新日期: 2023-09-27 18:17:56
我使用渐变为我的单元格背景。但是如果我使用
gradient.Frame = this.Bounds
使用UITableViewCell
的默认高度。我尝试使用GetHeightForRow
函数以及this.TableView.RowHeight = 60
,但每次梯度都具有单元格的默认高度的高度。
目前我正在使用
gradient.Frame = new RectangleF (this.Bounds.X, this.Bounds.Y, this.Bounds.Width, 60);
,但有一种方式,Bounds
有正确的高度(如设置与RowHeight
为例)?
代码是c#的,但Objective-C的解决方案将非常相似。
好的,我认为你想要的是这样的。在你的表视图委托方法中像这样设置它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell = [tableView dequeueReusableCellWithIdentifier:@"ReusableCellID"];
UIImage* image = [UIImage imageNamed:@"gradient.png"];
UIImageView* imgView = [[UIImageView alloc] initWithFrame:CGRectMake:(cell.frame.origin.x,cell.frame.origin.y,cell.frame.size.width,cell.frame.size.height)];
imgView.image = image;
[cell.backgroundView addSubview:imgView];
return cell;
}