我想以编程方式将图像设置为 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/