是否可以从界面构建器设置 UIView 边框属性? [英] Is it possible to set UIView border properties from interface builder?

查看:22
本文介绍了是否可以从界面构建器设置 UIView 边框属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以直接从界面构建器控制 UIView 边框属性(颜色、粗细等...),还是只能以编程方式进行?

解决方案

其实你可以通过interface builder来设置view层的一些属性.我知道我可以通过xcode设置图层的borderWidth和cornerRadius.borderColor 不起作用,可能是因为图层需要 CGColor 而不是 UIColor.

您可能必须使用字符串而不是数字,但它确实有效!

layer.cornerRadius图层边框宽度图层边框颜色

<块引用>

更新:layer.masksToBounds = true

<块引用>

更新:为 Keypath 选择适当的类型:

Is it possible to control UIView border properties (color, thickness, etc...) directly from interface builder or I can only do it programmatically?

解决方案

Actually you can set some properties of a view's layer through interface builder. I know that I can set a layer's borderWidth and cornerRadius through xcode. borderColor doesn't work, probably because the layer wants a CGColor instead of a UIColor.

You might have to use Strings instead of numbers, but it works!

layer.cornerRadius
layer.borderWidth
layer.borderColor

Update: layer.masksToBounds = true

Update: select appropriate Type for Keypath:

这篇关于是否可以从界面构建器设置 UIView 边框属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆