使用IB的“用户定义的运行时属性",这意味着使用IB.在UITableViewCell上 [英] Using IB's "User Defined Runtime Attributes" on a UITableViewCell
问题描述
我有一个静态的UITableView
,只有一个部分;该部分有两个UITableViewCell
,每个都有其自己的UIImageView
(请参见屏幕截图).我想修改单元格中使用的图像,以使其使用UIImageRenderingModeAlwaysTemplate
的渲染模式(以便图像将使用tintColor).
I have a static UITableView
with a single section; that section has two UITableViewCell
s each having its own UIImageView
(see screenshot). I would like to modify the image used in the cell so that it uses a rendering mode of UIImageRenderingModeAlwaysTemplate
(so that the image will honor tintColor).
我选择了UITableViewCell
,并在IB的用户定义的运行时属性"中进行了以下设置(请参见屏幕截图):
注意:2是UIImageRenderingModeAlwaysTemplate
的值.
I've selected the UITableViewCell
and set the following in IB's "User Defined Runtime Attributes" (see screenshot):
Note: 2 is the value of UIImageRenderingModeAlwaysTemplate
.
当我运行应用程序Xcode时,会产生以下警告:
When I run the app Xcode generates the following warning:
Failed to set (keyPath) user defined inspected property on (UIImageView): [<UIImageView 0x7fa490550d30> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.
知道我在做什么错吗?另外,我不想为此编写代码-如果可能的话,我希望坚持使用Storyboard.
Any idea what I'm doing wrong here? Also, I would like to not have to drop down to code for this - I want to stick with they Storyboard if possible.
谢谢!
推荐答案
由于imageView.image.renderingMode
是只读属性,因此如果不想放弃编写代码,则必须做其他事情.
Since imageView.image.renderingMode
is a read-only property you have to do something else if you don't want to drop down to writing code.
最简单的方法是在Images.xcassets中创建一个新条目.通过xcassets中的图像,您可以选择渲染为:模板图像.
The easiest way to accomplish this is to create a new entry in Images.xcassets. Images in xcassets allow you to select Render As: Template Image.
这篇关于使用IB的“用户定义的运行时属性",这意味着使用IB.在UITableViewCell上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!