简体   繁体   中英

Change UILabel's base class UIView to a Custom UIView?

As we all know the inheritence hierarchy of UILabel is:

UIView : UIResponder : NSObject

Now I want to change the UIView in the hierarchy to my custom UIView like:

CustomView: UIResponder : NSObject

So that all UILabels in my app Will have my custom UIView in their inheritence hierarchy.

That is not possible.

However, you can look for extending your class using a category. A category allows you to add methods to a class, but does not allow to change them. Here is a tutorial: http://www.tutorialspoint.com/objective_c/objective_c_categories.htm

Depending on what you are trying to achieve, subclassing UILable may still be an option. What exactly are you up to?

Edit: Well, theoretically it is possible chaning an object's superclass during runtime. However, I am not sure whether I really should recommend that to somebody who just asked your question. It is rather advanced, if advisable at all, and should be done by programmers who know exactly what they are doing. However, see this questions and answers: My isa-swizzling breaks KVO Dynamically change an object's superclass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM