iphone - 如何用静态图片设置 TableViewCell 的背景?

标签 iphone ios ios4 uitableview

我想以编程方式将图像设置为 TableViewCell 中每个单元格的背景。知道如何做到这一点吗?

提前致谢,

史蒂芬

最佳答案

您应该实现一个 tableView 委托(delegate)方法才能执行此操作,因为这是 Apple 的推荐。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]];
}

A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.

关于iphone - 如何用静态图片设置 TableViewCell 的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7325791/

相关文章:

iphone - 如何将表格单元格分隔符制作成我们想要的 View

ios4 - (XCode 4.0.2) 存档构建(为在应用商店上分发而构建)armv6 警告

iphone - GLPaint 更改画笔大小

iphone - UIApplicationDidEnterBackgroundNotification

iOS 应用程序 - 查找(未知)私有(private) api 调用

ios:滚动后自定义单元格中的微调器消失

ios - 如何将 QuickBlox VideoStream 渲染到对手视频 View 和自己的视频 View 中?

iphone - 如何在sqlite查询中传递表名

ios - 无法从 UICollectionViewCell 中删除图像

iphone - 在 iOS 中使用电子邮件 uri 方案的附件