问题
I got a question that i'm trying to figure out.
How can i set 2 different Subclasses in 1 UITextField?
I have installed a library ShowPassword
(via cocoapod) and currently i'm using it so users can see the password that they are typing.
But i have also installed another library that makes an awesome UITextField (also via cocoapods)
https://github.com/raulriera/TextFieldEffects
And with this library i can insert Subclass Hoshi
for example (which i have done in username text field)
How can i import both of them in password textfield?
回答1:
You cannot!
What you would need to be able to to is create a new class which inherits from both the TextFieldEffects
and the ShowPassword
. But Swift (same as Objective-C) does not support multiple inheritance (see this answer).
Your only option is to create a custom subclass from one of the classes and create the effect of the second one on your own in your subclass! Meaning that you have to write code to implement the functionality of one of the two desired effects.
Alternatively you can try to create an extension for one of the two library classes adding the logic from the second one. (basically the same thing)
It is highly unlikely that both subclasses would work together without any problems. As soon as both class override the same methods you are in a trouble since you have to decide which one really overrides it, etc.
来源:https://stackoverflow.com/questions/37158780/2-subclass-on-1-uitextfield