ios - 如何在 View Controller 中显示 UIControl 的子类

标签 ios swift interface-builder iboutlet uicontrol

我希望能够与我制作的 UIControl 进行交互,因此希望将它放在我的 ViewController 中。

我尝试过的

  • 我对 UIControl (1) 进行了子类化。
  • 然后,我向 View Controller 添加了一个 UIView,并为其分配了新类 (2)。

但是在 Interface Builder 中,我无法将 socket 设置为新类 (1) 中包含的按钮?!

1:1



2:2



UIControl's documentation确认它是 UIView 的子类,因此我应该能够连接 socket ,对吗?

我在这里缺少什么? :/

最佳答案

当然,您无法添加 IBOutlet,因为您添加到 WeekdayControl 的按钮位于 UIViewController 中,您无法将 Outlet 添加到 WeekdayControl,按钮仅是WeekdayControl的 subview ,UIViewController在这里是老大,你只能将outlet添加到UIViewController。 (抱歉我的英语)

更好地在 WeekdayControl 中以编程方式创建按钮。

关于ios - 如何在 View Controller 中显示 UIControl 的子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30374372/

相关文章:

swift - 弱 View 引用在临时添加到 View 层次结构后不会被释放

swift - 带有 SwiftUI View 的 UIKit TabBar

swift - 更改页面控件的位置不起作用

ios - 如何使用自动布局约束调整嵌入式 UIViewController 的大小和位置?

objective-c - 一个应用程序代理,两个窗口

ios - 从 nsdata 获取字节附加额外的垃圾字符

ios - swift/SpriteKit : evenly distribute SKShapeNodes horizontally and vertically into a grid

ios - 在 IOS 中设置日期选择器以仅选择日期和月份

ios - 如何将 Xcode Storyboard 的 "Simulated Metrics"工具栏连接到实际的 IBOutlet UIToolbar?

ios - 调用 alloc init 时 UIImagePickerController 真的很慢