【发布时间】:2009-10-12 19:28:26
【问题描述】:
哇,那是一口。 :)
我们已经在customizing the more menu (table view) in a tab bar 上看到了一个不错的帖子。
对于我们的下一个技巧......如何将背景图像添加到表格单元格?
我认为我可以在我的 More Table View 的数据源类中重写 tableView:cellForRowAtIndexPath: (方法见前面的链接)。唉,它只会改变每个单元格左右的图像和附件视图下的背景。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Let the original Data Source get a hold of the cell first.
UITableViewCell *cell = [originalDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
// If we override the textColor, that works fine. (Commented out for now.)
//cell.textLabel.textColor = [UIColor whiteColor];
// If we override the background view … that doesn't work so well.
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBackground.png"]];
return cell;
}
我知道,imageNamed: 是邪恶的,也许我应该创建一个背景图像并在整个过程中重复使用它(而不是分配多个 UIImageView 对象)。除了这些东西,还有什么想法吗? (我也尝试调整 textLabel 的 backgroundColor,但无济于事……除非我在那里做错了。)
【问题讨论】:
-
你有想过这个吗?
-
我没有,但其他人做到了。在此处查看 Ian1971 的 SO 答案:stackoverflow.com/questions/438381/…
标签: iphone uitableview uitabbarcontroller background-image