Uikit provides a set of controls: Uiswitch switches, Uibuttonbutton, Uisegmentedcontrol segmented controls, UISlider sliders, Uitextfield text field controls,
Uipagecontrol the paging control.
Controls are useful enhancements and additions to UIView derived classes and can be attached directly to navigation bars, table cells, and even larger objects.
The base classes of these controls are Uicontrol, and Uicontrol derive from the UIView class, so each control has a very multi-view feature that contains the ability to attach to other views. All
Controls have a common set of properties and methods.
So learning controls, we first learn Uicontrol
Property
enabled
the control is enabled by default. To disable a control, you can set the Enabled property to No, which causes the control to ignore any touch events. When disabled, the control can also display itself in a different way, for example, to become grayed out. Although the subclass of the control is complete, this property exists in Uicontrol.
Selected
When the user selects the control, the Uicontrol class sets its selected property to Yes. Subclasses sometimes use this property to let a control choose itself, or to behave differently.
Contentverticalalignment
controls how to lay out their own content in the vertical direction. By default, the content is top-to-bottom, and for text fields, it may be changed to Uicontrolcontentverticalalignmentcenter. For this field, the following values can be used:
1.Uicontrolcontentverticalalignmentcenter
2.Uicontrolcontentverticalalignmenttop
3.Uicontrolcontentverticalalignmentbottom
4.Uicontrolcontentverticalalignmentfill
contenthorizontalalignment
Horizontal Direction
1.Uicontrolcontenthorizontalalignmentcenter
2.Uicontrolcontenthorizontalalignmenttop
3.Uicontrolcontenthorizontalalignmentbottom
4.Uicontrolcontenthorizontalalignmentfill
Event notification
The Uicontrol class provides a standard mechanism for registering and receiving events. This allows you to specify a method in which your control notifies the proxy class when a particular event occurs. Suppose you want to register an event and be able to use the Addtarget side
Method:
[mycontrol addtarget:mydelegate Action: @selector (Myactionmethod:) forControlEvents: Uicontroleventvaluechanged];
Events can be combined with logical OR, so that multiple events can be specified again in a separate addtarget call. The following events are supported by the base class Uicontrol, and are applicable to all controls unless otherwise noted
Uicontroleventtouchdown
Single Touch Press event: The user touches the screen, or when a new finger falls.
Uicontroleventtouchdownrepeat
Multi-touch Press event, touch count greater than 1: when the user presses the second to third or fourth finger.
uicontroleventtouchdraginside
When a touch is dragged inside the control pane.
uicontroleventtouchdragoutside
When a touch is dragged outside the control form.
Uicontroleventtouchdragenter
When a touch is dragged from outside the control form to inside.
uicontroleventtouchdragexit
When a touch is dragged from inside the control form to the outside.
UIControlEventTouchUpInside
All touch lift events within the control.
uicontroleventtouchupoutside
All touch lift events outside the control (the touch must start with the inside of the control to send a notification).
Uicontroleventtouchcancel
All touch Cancel event, that is, one touch is canceled due to too many fingers, or is locked or interrupted by a phone call.
uicontroleventtouchchanged
Sends a notification when the value of the control has changed. Used for sliders, segmented controls, and other controls that take values. You can configure when a slider control sends notifications when the slider is dropped, or when it is dragged.
Uicontroleventeditingdidbegin
Send a notification when you start editing in a text control.
uicontroleventeditingchanged
A notification is sent when the text in the text control is changed.
Uicontroleventeditingdidend
Sends a notification when the edit ends in a text control.
uicontroleventeditingdidonexit
Sends a notification when the edit is finished by pressing the ENTER key (or equivalent behavior) within the text control.
uicontroleventalleditingevents
Notifies all events about text editing.
Uicontroleventallevents
Notifies all events.
To delete the corresponding action for one or more events, you can use the Removetarget method of the Uicontrol class. You can delete all actions for a given event target by using the nil value:
[MyControl removetarget:mydelegate Action:nil forcontrolevents:uicontroleventallevents];
To get a list of all specified actions for a control, you can use the Alltargets method. This method returns a Nsset that includes a complete list of events:
nsset* myactions = [Myconreol alltargets];
In addition, you can use the Actionsfortarget method to get a list of all the actions for a specific event target:
nsarray* myactions = [MyControl actionfortarget:uicontroleventvaluechanged];
Suppose you have designed a custom control class that can use the Sendactionsforcontrolevent method to send notifications for major Uicontrol events or for your own defined events. For example, assuming that your control's value is changing, you can
Send the corresponding notification, the code of the control can specify the time target, this notification will be propagated to these specified targets. Cases:
[Self sendactionsforcontrolevents:uicontroleventvaluechanged];
When the entrusted class gets an event notification, he receives a pointer to the sender of the event. The following sample is used to handle the event of a segmented control, and your action method should follow a similar approach:
-(void) Myaction: (ID) sender{
uisegmentedcontrol* control = (uisegmentedcontrol*) sender;
if (Control = = myControl1) {
/ * Query control Get value * /
/* Respond to MYCONTROL1 's action */
}
}