gpt4 book ai didi

ios - 如何在不设置任何 @IBinspectable 属性的情况下在 Storyboard 中的 UIView 上实时执行更改?

转载 作者:行者123 更新时间:2023-11-29 01:41:49 25 4
gpt4 key购买 nike

在 Storyboard 中,我有 UITextField,我还创建了自定义类:

class WLTextField: UITextField {

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

layer.cornerRadius = 2
layer.masksToBounds = true
layer.borderColor = UIColor.grayColor().CGColor
layer.borderWidth = 1
}
}

然后将这个类附加到我的UITextField:

enter image description here

但是,Storyboard 中没有这方面的结果。我怎样才能做到这一点?我需要像使用 @IBDesignables 一样获得这样的效果。但是因为我知道我需要为每个文本字段设置什么,所以我不需要设置一个值然后在 didSet 中更新它。

我是否需要至少设置一个值才能在某些 UIView 的 Storyboard 中进行更改?

最佳答案

为了在 Interface Builder 中呈现组件,您必须将类标记为 @IBDesignable 并且您必须实现初始化 init(frame: CGRect) -

@IBDesignable class WLTextField: UITextField {

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupLayer()
}

required override init(frame: CGRect) {
super.init(frame: frame)
setupLayer()
}

func setupLayer () {
layer.cornerRadius = 2
layer.masksToBounds = true
layer.borderColor = UIColor.grayColor().CGColor
layer.borderWidth = 1
}
}

关于ios - 如何在不设置任何 @IBinspectable 属性的情况下在 Storyboard 中的 UIView 上实时执行更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32310101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com