界面生成器中 UIView 的边框颜色不起作用? [英] UIView's border color in Interface builder doesn't work?
问题描述
我正在尝试通过 IB 设置视图的图层属性.除了边框的颜色(属性 layer.borderColor
)外,一切正常:
I am trying to set up a view's layer properties via IB. Everything works except for color of the border (property layer.borderColor
):
我记得一年前遇到过这个问题,我最终以编程方式解决了这个问题.而且,我仍然可以通过编程方式执行此操作,但我很好奇为什么 layer.borderColor
属性从不通过界面构建器工作.我不想导入 QuartzCore
,然后仅仅因为这个而编写额外的代码行,这似乎是一种矫枉过正.
I remember running into this problem a year ago and I ended up doing it programatically. And still, I can do this programmatically, but I am curious why the layer.borderColor
property never works via interface builder. I don't want to import QuartzCore
, and then write extra line of code just because of this, seems like an overkill.
推荐答案
可以这样做,但它不是内置功能.这是因为 User Defined Runtime Attributes 面板中的 Color
类型创建了一个 UIColor
,但 layer.borderColor
持有一个 CGColorRef代码>类型.不幸的是,没有办法在 Interface Builder 中分配
CGColorRef
类型.
It's possible to do this, but it's not a built-in feature. This is because the Color
type in the User Defined Runtime Attributes panel creates a UIColor
, but layer.borderColor
holds a CGColorRef
type. Unfortunately, there's no way to assign a CGColorRef
type in Interface Builder.
但是,这可以通过代理属性实现.请参阅Peter DeWeese 的回答对另一个问题的可能解决方案.他的回答定义了一个类别,允许通过 Interface Builder 设置代理颜色.
However, this is possible through a proxy property. See Peter DeWeese's answer to a different question for a possible solution to this problem. His answer defines a category that allows a proxy color to be set through Interface Builder.
这篇关于界面生成器中 UIView 的边框颜色不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!