【问题标题】:Using gradient as background in UITableViewCell [duplicate]在 UITableViewCell 中使用渐变作为背景 [重复]
【发布时间】:2010-11-15 13:03:46
【问题描述】:

可能重复:
UITableViewCell with custom gradient background, with another gradient as highlight color

嘿,我想为我的 tableview 单元格添加一个轻微的渐变背景,让它们看起来更有趣。我应该只制作图像并将其放在背景上还是使用代码来绘制它?如果我应该使用代码来做到这一点,你能解释一下吗? PS。我有一个自定义单元格

【问题讨论】:

    标签: cocoa-touch ios uikit uitableview


    【解决方案1】:

    首先制作图像,例如gradient.jpeg。

    然后在您配置单元格的 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法中完成以下操作。

    UIImage *image = [UIImage imageNamed:@"gradient.jpeg"];

    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

    imageView.contentMode = UIViewContentModeScaleToFill;

    cell.backgroundView = imageView;

    [imageView 发布];

    是的,通过制作图像,我的意思是在一些功能强大的图像编辑器上完成它。

    【讨论】:

    • 我似乎无法让它显示在我的手机背面。我正在做你说的,但它不会显示:S
    • 对我来说可能听起来很傻,但是您是否已将创建的图像添加到项目的 Resources 文件夹中?如果是这样,您能否发布一些有关您在上述方法中所做的相关代码?我可以为您提供帮助,因为上述内容在我的一个项目中对我最有效:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多