Is there a way for Interface Builder to render IBDesignable views which don't override drawRect:

前端 未结 8 587
不知归路
不知归路 2020-12-02 03:45

I very rarely override drawRect in my UIView subclasses, usually preferring to set layer.contents with pre-rendering images and often employing multiple sublaye

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 04:40

    In my case, there were two problems:

    1. I did not implement initWithFrame in custom view: (Usually initWithCoder: is called when you initialize via IB, but for some reason initWithFrame: is needed for IBDesignable only. Is not called during runtime when you implement via IB)

    2. My custom view's nib was loading from mainBundle: [NSBundle bundleForClass:[self class]] was needed.

提交回复
热议问题