gpt4 book ai didi

ios - 在 Storyboard本身中将自定义类添加到 UILabel 时如何查看更改?

转载 作者:行者123 更新时间:2023-11-28 11:37:44 25 4
gpt4 key购买 nike

我已将自定义类添加到 UILabel。自定义类是:

@IBDesignable class CustomLabel: UILabel {

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.setup()

}

override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}

override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
setup()
}

private func setup() {
self.textColor = UIColor.blue
}
}

但我看不到 Storyboard的变化。它如何能够看到界面构建器中的变化??

最佳答案

您必须添加 IBInspectable 属性才能查看 Storyboard中的更改

这里是例子

@IBDesignable class RoundedTextField: UITextField {


@IBInspectable var cornerRadius:CGFloat = 0 // You will see this in storyboard
@IBInspectable var borderColor:UIColor = .green // You will see this in storyboard

override func awakeFromNib() {
super.awakeFromNib()
self.borderStyle = .none
self.layer.cornerRadius = cornerRadius
self.layer.borderColor = borderColor.cgColor
self.layer.borderWidth = 2.0
self.backgroundColor = UIColor.white
self.layer.masksToBounds = true
}
}

不要忘记设置类

enter image description here

这里是你如何在 Storyboard中看到

enter image description here

关于ios - 在 Storyboard本身中将自定义类添加到 UILabel 时如何查看更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54603708/

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