<分区>
我已经尝试了很多次,只是为了在 ImageView 上获得一个简单的边框,但似乎没有任何效果。这些是我现在的事件设置:
但是结果还是没有任何边框。
我的设置中缺少什么?
标签 ios swift uiimageview
最佳答案
layer.borderColor
是一个 CGColorRef
。但是界面生成器传递了一个 UIColor
。您有两个选择:
1 - 在代码中设置边框颜色:
self.imageView.layer.borderColor = UIColor.blue.cgColor
2 - 使用 borderColor
属性扩展 UIImageView
或 UIView
并使用 @IBDesignable
和 @ IBInspectable
,以便该属性在界面生成器中可见。使用此新属性作为 layer.borderColor
的代理。
@IBDesignable
extension UIView {
@IBInspectable
var borderColor: UIColor? {
get {
if let cgColor = self.layer.borderColor {
return UIColor(cgColor: cgColor)
}
return nil
} set {
self.layer.borderColor = newValue?.cgColor
}
}
}
相关文章:
关于ios - 无法在 UIImageView 上设置边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48715294/