【问题标题】:IOS/Objective-C: Set imagerenderingmode of image with Storyboard and codeIOS/Objective-C:使用Storyboard和代码设置图像的imagerenderingmode
【发布时间】:2018-08-19 04:48:50
【问题描述】:

我在情节提要中创建了一个按钮,现在我想在代码中更改它的色调。单独更改色调没有效果,因为我认为我需要设置 UIImageRenderingMode。但是,我的代码不起作用:

在故事板中创建按钮时,任何人都可以建议更改代码中uiimagerenderingmode 的语法吗?

以下没有效果:

 self.callButton.imageView.tintColor = [UIColor redColor];

以下抛出错误property uiimagerenderingmodealwaystemplate not found

[self.callButton.image.imageWithRenderingMode UIImageRenderingModeAlwaysTemplate];

感谢您的任何建议。

【问题讨论】:

  • 错字/语法问题 - 你想要[self.callButton.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]

标签: ios objective-c uiimageview


【解决方案1】:

解决这个问题的一种方法:

在你的故事板中,make sure to set "Render as" to "Template Image"(图像本身应该是黑白的)然后你可以调用self.callButton.tintColor = [UIColor redColor]

像这样:

附言我正在为我的图像使用 PDF 文件,这就是为什么我选择了“单一比例”并将“保留矢量数据”复选框设置为打开;如果您使用的是 PNG,则该复选框应设置为关闭,并且您应该有 @2x 图形。

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多