如何在视图控制器中显示 UIControl 的子类
How to show subclass of UIControl in View Controller
我希望能够与我制作的 UIControl 交互,因此希望它在我的 ViewController.
我试过的
- 我子class编辑了 UIControl (1)。
- 然后我向我的视图控制器添加了一个 UIView 并为其分配了新的 class (2)。
但是在 Interface Builder 中,我无法将我的插座设置为新 class (1)?!
中包含的按钮
1:
2:
UIControl's documentation 确认它是 UIView 的子class,因此我应该可以连接插座,对吗?
我在这里错过了什么? :/
必读:-
You cannot use the UIControl class directly to instantiate controls.
It instead defines the common interface and behavioral structure for
all its subclasses.
The main role of UIControl is to define an interface and base
implementation for preparing action messages and initially dispatching
them to their targets when certain events occur
所以,你做错了,如果你真的需要制作自定义视图或自定义控件,那么你可以直接通过创建自定义 UIView 并将插座直接与视图连接来完成。
我认为您错过了 objective 对 UIControl 进行子类化,它不授予创建插座的权利,因为它是 UIView 的子类,只需阅读这行它在文档:-
Subclassing Notes
You may want to extend a UIControl subclass for either of two reasons:
To observe or modify the dispatch of action messages to targets for
particular events
To do this, override sendAction:to:forEvent:, evaluate the passed-in
selector, target object, or UIControlEvents bit mask, and proceed as
required.
To provide custom tracking behavior (for example, to change the
highlight appearance)
To do this, override one or all of the following methods:
beginTrackingWithTouch:withEvent:,
continueTrackingWithTouch:withEvent:, endTrackingWithTouch:withEvent:.
当然你不能添加 IBOutlet,因为你添加到 WeekdayControl
的按钮在 UIViewController
中,你不能将 Outlet 添加到 WeekdayControl
,按钮只有子视图WeekdayControl
,UIViewController
是这里的老大,只能给UIViewController
添加outlet。 (对不起我的英语)
最好在 WeekdayControl 中以编程方式创建按钮。
我希望能够与我制作的 UIControl 交互,因此希望它在我的 ViewController.
我试过的
- 我子class编辑了 UIControl (1)。
- 然后我向我的视图控制器添加了一个 UIView 并为其分配了新的 class (2)。
但是在 Interface Builder 中,我无法将我的插座设置为新 class (1)?!
中包含的按钮1:
2:
UIControl's documentation 确认它是 UIView 的子class,因此我应该可以连接插座,对吗?
我在这里错过了什么? :/
必读:-
You cannot use the UIControl class directly to instantiate controls. It instead defines the common interface and behavioral structure for all its subclasses.
The main role of UIControl is to define an interface and base implementation for preparing action messages and initially dispatching them to their targets when certain events occur
所以,你做错了,如果你真的需要制作自定义视图或自定义控件,那么你可以直接通过创建自定义 UIView 并将插座直接与视图连接来完成。
我认为您错过了 objective 对 UIControl 进行子类化,它不授予创建插座的权利,因为它是 UIView 的子类,只需阅读这行它在文档:-
Subclassing Notes
You may want to extend a UIControl subclass for either of two reasons:
To observe or modify the dispatch of action messages to targets for particular events
To do this, override sendAction:to:forEvent:, evaluate the passed-in selector, target object, or UIControlEvents bit mask, and proceed as required.
To provide custom tracking behavior (for example, to change the highlight appearance)
To do this, override one or all of the following methods: beginTrackingWithTouch:withEvent:, continueTrackingWithTouch:withEvent:, endTrackingWithTouch:withEvent:.
当然你不能添加 IBOutlet,因为你添加到 WeekdayControl
的按钮在 UIViewController
中,你不能将 Outlet 添加到 WeekdayControl
,按钮只有子视图WeekdayControl
,UIViewController
是这里的老大,只能给UIViewController
添加outlet。 (对不起我的英语)
最好在 WeekdayControl 中以编程方式创建按钮。