我已经向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
}
}

但我看不到故事板的变化。它如何能够看到界面生成器中的更改??

最佳答案

必须添加IBInspectable属性才能查看情节提要中的更改
下面是一个例子

@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
      }
}

别忘了上课
ios - 在 Storyboard 中将自定义类添加到UILabel时如何查看更改?-LMLPHP
这是你在stoyrboard看到的
ios - 在 Storyboard 中将自定义类添加到UILabel时如何查看更改?-LMLPHP

10-07 12:24
查看更多