ios - 单元格背景图像模式

标签 ios objective-c uitableview

我在 UITableView 中有一个单元格,它使用 colorWithPatternImage 将图像作为背景。我想在此图像上设置一种模式以适合单元格,即 UIViewContentModeScaleAspectFill 等。(我将仔细研究并找到最适合我使用的模式)

这是我的代码:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath
                                                                                                      *)indexPath
{
    if((indexPath.row)==1)
        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"homeScreen-buttons.jpg"]];

}

那么我该如何编辑我的代码来添加我需要的东西呢?谢谢

最佳答案

您可以设置单元格层的内容,试试这个:

cell.layer.contents = (id)[UIImage imageNamed:@"homeScreen-buttons.jpg"].CGImage;

关于ios - 单元格背景图像模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30794735/

相关文章:

ios - 如何实例化第二个 ViewController 并停止第一个 ViewController 的方法

iphone - 自 iOS 8.3 以来,自定义 UITableView 原型(prototype)单元格约束有什么变化吗?

iphone - 滑动删除导致我的 UITable 出现奇怪的错误

ios - 将多个数组放入字典

ios - 调用目录分机-找不到分机

html - IOS 设备出现 HTML 表单输入问题(类型 = 文本)

ios - 如何使用 iOS Quartz 2D 绘图绘制这个复杂的形状?

ios - 音频文件自己播放

iphone - 在 Objective-C 的数组中查找值

ios - `titleForHeaderInSection` 似乎在 iOS 中的 viewDidLoad 之前被调用