Swift 为 UI 元素分配多个类 [英] Swift assigning multiple classes to UI element

查看:25
本文介绍了Swift 为 UI 元素分配多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Swift 中将多个自定义类分配给同一个 UI 元素?

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

我有一个 UITextField,我需要用 Spring(动画库)来制作动画,我还需要在同一个 UITextField 上使用一些其他库来提供一些其他功能.我通常在故事板的身份检查器自定义类部分分配自定义类,但我找不到分配多个类的方法.我还尝试创建一个新类并从我尝试使用的这两个库中继承,但我认为您不能在 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.

推荐答案

你不能,Swift 不支持多重继承.一个对象可以实现多个协议,但只能从一个类继承.

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

这篇关于Swift 为 UI 元素分配多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆