Swift assigning multiple classes to UI element

天大地大妈咪最大 提交于 2021-01-27 22:21:11

问题


Is it possible to assign multiple custom classes to the same UI Element in Swift?

I have a UITextField that I need to animate with Spring(Animation library) and I also need to use some other library on the same UITextField that provides some other functionality. I usually assign the custom class in the identity inspector custom class section in the storyboard but I can't find a way to assign multiple classes. I also tried to create a new class and inherit from both of these libraries that I am trying to use but I don't think you can have multiple inheritances in Swift.


回答1:


You can't, Swift does not support multiple-inheritance. An object can implement multiple protocols but only inherit from one class.




回答2:


For sorry this is not available in Swift ( Great C++ has it ) , so you have to select anyone and go with it




回答3:


Ok, I just came up with a great idea that fits my needs perfectly but it might not apply to everyone. Since one of the libraries I was trying to use was purely for animation, I placed my UITextView inside a view, inherited the animation library for the view and inherited the other library for UITextView. Now I have both the animations working and the functionality.



来源:https://stackoverflow.com/questions/50727692/swift-assigning-multiple-classes-to-ui-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!