正确设置UITableViewCell的高度,以便UITableviewCell子类具有正确的Bounds

时间:2014-08-14 14:30:31

标签: c# ios uitableview xamarin.ios xamarin

我正在为我的细胞背景使用渐变。但是,如果我使用

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解决方案非常相似。

1 个答案:

答案 0 :(得分:0)

好吧,我认为你想要的是这样的......在你的表视图中,委托方法设置如下:

- (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;

}