加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iPhone – 如何在UITableView单元格中设置背景图像?

发布时间:2020-12-14 19:00:02 所属栏目:百科 来源:网络整理
导读:我创建了自定义单元格.我有分组样式的表视图.现在我想将Backgroung图像放到不同部分的每个单元格.如何设置自定义单元格的背景图像. 以下是创建自定义单元格的代码. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,305,90)]; // view.background
我创建了自定义单元格.我有分组样式的表视图.现在我想将Backgroung图像放到不同部分的每个单元格.如何设置自定义单元格的背景图像.
以下是创建自定义单元格的代码.

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,305,90)];

// view.backgroundColor = [UIColor darkGrayColor];

UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(11,9,61,55)];
// NSLog(@"imageArray%@",[play.imageArray count]);
NSString *img=[play.imageArray objectAtIndex:indexPath.row];
NSLog(@"img=%@",img);
imageV.image = [UIImage imageNamed:img];
[view addSubview:imageV];
[imageV release];

UILabel *lblAchievementName = [[UILabel alloc] initWithFrame:CGRectMake(90,10,168,21)];
lblAchievementName.text = [play.listData objectAtIndex:indexPath.row];
lblAchievementName.backgroundColor=[UIColor clearColor];

lblAchievementName.textColor=[UIColor orangeColor];
[lblAchievementName setFont:[UIFont fontWithName:@"Arial Black" size:16.5]];

[view addSubview:lblAchievementName];
[lblAchievementName release]


[cell.contentView addSubview:view];

return cell;

现在如何为此自定义视图设置背景图像?

解决方法

您可以尝试这个可以帮助您的代码.

将此代码放在cellForRowAtIndexPath方法中

UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(20,20,277,58)];
    av.backgroundColor = [UIColor clearColor];
    av.opaque = NO;
    av.image = [UIImage imageNamed:@"categorytab1.png"];
    cell.backgroundView = av;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读