Uicontrol-ios Development

Source: Internet
Author: User
Tags uicontrol

Uikit provides a set of controls: Uiswitch switch, UIButton button, Uisegmentedcontrol segmented control, UISlider slider, Uitextfield text field control,

Uipagecontrol the paging control.

Controls are practical enhancements and additions to UIView derived classes and can be attached directly to navigation bars, table cells, and even larger objects.

The base classes for these controls are Uicontrol, and Uicontrol derive from the UIView class, so each control has many views of its own, including 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 different ways, such as turning gray to be unavailable. Although it is done by a subclass of the control, 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 the contents of their own are laid out vertically. By default, the content is top-to-bottom, and for text fields, it may be changed to Uicontrolcontentverticalalignmentcenter. For this field, you can use the following values:

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. If you want to register an event, you can use the Addtarget party

Method:

[MyControl addtarget:mydelegate Action: @selector (Myactionmethod:) forcontrolevents:uicontroleventvaluechanged];

Events can be combined with logical OR, so 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 within the control window.

Uicontroleventtouchdragoutside

When a touch is dragged outside the control window.

Uicontroleventtouchdragenter

When a touch is dragged from outside the control window to the inside.

Uicontroleventtouchdragexit

When a touch is dragged from inside the control window 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 cancellation events, that is, one touch is canceled because it has 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

Sends a notification when the text control starts editing.

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 the specified actions for a control, you can use the Alltargets method. This method returns a Nsset that contains 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 particular event target:

nsarray* myactions = [MyControl actionfortarget:uicontroleventvaluechanged];

If you have designed a custom control class, you can use the Sendactionsforcontrolevent method to send notifications for basic Uicontrol events or your own custom events. For example, if your control's value is changing, you can

Sends a notification that the control's code can specify a time target that will be propagated to those specified targets. Cases:

[Self sendactionsforcontrolevents:uicontroleventvaluechanged];

When the delegate class gets an event notification, he receives a pointer to the sender of the event. The following example 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 */

}
}

Uicontrol-ios Development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.