在iphone应用程序的分组表视图的每个部分中添加不同的图像作为背景
我想使用分组表视图创建一个Iphone应用程序。我创建了分组表视图。我的分组表视图有三个部分。我想为分组表视图中的每个部分添加不同的图像作为背景 如果在每个部分中使用以下代码,则总视图将显示在同一图像中在iphone应用程序的分组表视图的每个部分中添加不同的图像作为背景,iphone,Iphone,我想使用分组表视图创建一个Iphone应用程序。我创建了分组表视图。我的分组表视图有三个部分。我想为分组表视图中的每个部分添加不同的图像作为背景 如果在每个部分中使用以下代码,则总视图将显示在同一图像中 NSString *backgroundPath = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"]; UIImage *backgroundImage = [UIImage imageWi
NSString *backgroundPath = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"];
UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundPath];
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage];
tableView.backgroundColor = backgroundColor;
[backgroundColor release];
试试这个:
- (void) tableView: (UITableView *) tableView willDisplayCell: (UITableViewCell *) cell forRowAtIndexPath: (NSIndexPath *) indexPath {
UIColor * color;
switch (indexPath.section) {
case 0:
color = [UIColor colorWithPatternImage: [UIImage imageNamed: @"...0"]]; break;
case 1:
color = [UIColor colorWithPatternImage: [UIImage imageNamed: @"...1"]]; break;
case 2:
color = [UIColor colorWithPatternImage: [UIImage imageNamed: @"...2"]]; break;
default:
color = [UIColor colorWithPatternImage: [UIImage imageNamed: @"..."]]; break;
break;
}
cell.backgroundColor = color;
}
将
..
和..X
替换为要使用的图像。添加更多或删除一些case
s以获得正确的节数。我认为您无法做到这一点:)好的。在我读了你的答案后,我不确定你是想改变单元格的背景还是表格的背景,但我很高兴你能成功。