如何在UITableView单元格中设置背景图像? [英] How to set Background image in UITableView cell?
本文介绍了如何在UITableView单元格中设置背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了自定义单元格。我有带有分组样式的表格视图。现在我想将Backgroung图像放到不同部分的每个单元格中。如何设置自定义单元格的背景图像。
以下是创建自定义单元格的代码。
I have Created custom cell.And i have table view with Grouped style.Now i want to put Backgroung image to each cell of different section.How to set the background image of custom cell. Here is the code for creating the custom cell.
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 305, 90)];
// view.backgroundColor = [UIColor darkGrayColor];
// 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;
现在如何设置此自定义视图的背景图像?
Now how to set the backgroung image for this custom view?
推荐答案
您可以尝试这段代码来帮助您。
You can try this code that will help you.
将此代码放入 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;
这篇关于如何在UITableView单元格中设置背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文