IOS/Objective-C: 使用 Storyboard 和代码设置图像的 imagerenderingmode
IOS/Objective-C: Set imagerenderingmode of image with Storyboard and code
我在故事板中创建了一个按钮,现在我想在代码中更改它的色调。单独更改色调没有效果,因为我认为我需要设置 UIImageRenderingMode。但是,我的代码不起作用:
谁能建议在情节提要中创建按钮时在代码中更改 uiimagerenderingmode
的语法?
以下无效:
self.callButton.imageView.tintColor = [UIColor redColor];
以下抛出错误 property uiimagerenderingmodealwaystemplate not found
:
[self.callButton.image.imageWithRenderingMode UIImageRenderingModeAlwaysTemplate];
感谢您的任何建议。
解决此问题的一种方法:
在你的故事板中,make sure to set "Render as" to "Template Image"(图像本身应该是黑白的)然后你可以调用 self.callButton.tintColor = [UIColor redColor]
。
像这样:
p.s。我为我的图像使用 PDF 文件,这就是我选择 "Single Scale" 并将 "Preserve Vector Data" 复选框设置为打开的原因;如果您使用的是 PNG,则该复选框应设置为关闭并且您应该有 @2x
个图形。
我在故事板中创建了一个按钮,现在我想在代码中更改它的色调。单独更改色调没有效果,因为我认为我需要设置 UIImageRenderingMode。但是,我的代码不起作用:
谁能建议在情节提要中创建按钮时在代码中更改 uiimagerenderingmode
的语法?
以下无效:
self.callButton.imageView.tintColor = [UIColor redColor];
以下抛出错误 property uiimagerenderingmodealwaystemplate not found
:
[self.callButton.image.imageWithRenderingMode UIImageRenderingModeAlwaysTemplate];
感谢您的任何建议。
解决此问题的一种方法:
在你的故事板中,make sure to set "Render as" to "Template Image"(图像本身应该是黑白的)然后你可以调用 self.callButton.tintColor = [UIColor redColor]
。
像这样:
p.s。我为我的图像使用 PDF 文件,这就是我选择 "Single Scale" 并将 "Preserve Vector Data" 复选框设置为打开的原因;如果您使用的是 PNG,则该复选框应设置为关闭并且您应该有 @2x
个图形。