How to override both initWithFrame: and initWithCoder: in subclass of UIView?

后端 未结 2 1691
梦如初夏
梦如初夏 2020-12-14 16:14

I\'m trying to subclass UIView. I already have some designated initializer and I want to have possibility for my custom view to be initialized either from code or from Nib f

2条回答
  •  渐次进展
    2020-12-14 17:12

    As you said:

    initWithFrame: - It is recommended that you implement this method. You can also implement custom initialization methods in addition to, or instead of, this method.

    initWithCoder: - Implement this method if you load your view from an Interface Builder nib file and your view requires custom initialization.

    What I would do is just a method that both would call, which would have common behavior you want to implement in your UIView.

提交回复
热议问题