UIAppearance proxy for custom objects

前端 未结 4 562
小鲜肉
小鲜肉 2020-12-24 14:48

I have a custom object, it inherits from NSObject. This object does \"some things\", one of it is creating an UIView with some UIKit objects (UILabel, UIButtons ecc ecc...)

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-24 15:25

    Check out http://logicalthought.co/blog/2012/10/8/uiappearance-and-custom-views

    Basically you just need to tag your properties with UI_APPEARANCE_SELECTOR and everything works as long as your class is a subclass of UIView which will handle the actual vending of the private _UIAppearance class.


    Edit:

    You're probably better off just rolling your own solution using a singleton and some class methods rather than attempting to do something scary with the runtime. It doesn't look like UIAppearance supports your use case.

    On the other hand, you could stick each object you vend in a private UIView subclass and then vend instances of that subclass instead. Then you can forward appearance messages sent to your NSObject to the instances you vend and use appearanceWhenContainedIn:. That could get messy though and could be confusing for consumers of your class.

提交回复
热议问题