@IBDesignable crashing agent

前端 未结 10 899
自闭症患者
自闭症患者 2020-11-29 02:59

When I write my own UIButton-extended class and make it @IBDesignable, I receive two errors in Interface Builder, namely:

  • Main.storyb
10条回答
  •  温柔的废话
    2020-11-29 03:47

    Xcode's Interface Builder requires that you implement both or neither initializers for @IBDesignable classes to render properly in IB.

    If you implement required init(coder aDecoder: NSCoder) you'll need to override init(frame: CGRect) as well, otherwise "the agent will crash" as seen in the errors thrown by Xcode.

    To do so add the following code to your class:

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

提交回复
热议问题