【问题标题】:UITableViewCell background image not displayingUITableViewCell 背景图片不显示
【发布时间】:2012-05-16 10:11:32
【问题描述】:

我正在尝试使用以下代码向UITableViewCell 添加背景图片:

UIImage *bgImage=[UIImage imageNamed:@"green-cell-row.png"];
UIImageView *bgForFirst=[[UIImageView alloc] initWithImage:bgImage];
cell.backgroundView=bgForFirst;
[cell.contentView addSubview:venueDisplayImage];
[cell.contentView addSubview:venueDisplayName1];
[cell.contentView addSubview:venueDisplayName2];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
cell.selectionStyle = UITableViewCellSelectionStyleGray;

但是,我在它周围的空白处得到了场地显示名称。解决此问题并正确添加我的背景图片的最佳方法是什么?

【问题讨论】:

标签: iphone ios uitableview background-image


【解决方案1】:

试试这个方法:

1) TabelView 设置背景如下:

tblView.backgroundView.alpha = 0.0;
tblView.backgroundColor=[UIColor clearColor];

2) 在tableview的cellForRowAtIndexPath og委托方法中添加图片视图:

UIImageView *bckView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 300,80)];
cell.backgroundView.alpha = 0.0;
cell.backgroundColor=[UIColor clearColor];
bckView.image = [UIImage imageNamed:@"cell.png"];
bckView.contentMode = UIViewContentModeScaleToFill;
[cell.contentView addSubview:bckView];

【讨论】:

    【解决方案2】:

    您是否尝试将backgroundColorvenueDisplayName 更改为[UIColor clearColor][UIColor greenColor]

    出于性能原因,请尽量避免在UITableViewCell 中使用非透明视图。

    【讨论】:

    • novenueDisplayName 是 UILabel,我用框架对其进行初始化,然后将其添加到单元格中
    【解决方案3】:

    你必须使用 cell 的属性 您可以使用 2 个属性 1)cell.backgroundColor 2) cell.backgroundView

        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageName:@""]];
    

    在第二种情况下,您必须将任何视图设置为背景视图

    【讨论】:

      猜你喜欢
      • 2020-09-11
      • 1970-01-01
      • 2018-08-10
      相关资源
      最近更新 更多