OBJECTIVE-C: Reprint: Use of Uicontrol

Source: Internet
Author: User
Tags uicontrol

main functions:
UIContol(控件是所有控件的基类 如:(UIButton)按钮主要用于与用户交互,通常情况下我们不会直接使用UIControl,而是子类化它。
Common Properties:BOOL enabled
   空间默认是启用的,要禁用控件,可以将enabled属性设置为NO,这样将导致控件会略任何触摸控件事件。被禁用后,控件还可以用不同的方式显示自己,

such as turning gray is not available. It is done by the subclass of the space, and this attribute exists in Uicontrol.

Example Demo:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(40, 60, 100, 60)];    button.backgroundColor = [UIColor orangeColor];    button.enabled = NO;    [button addTarget:self action:@selector(onButton) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:button];- (void)onButton{    NSLog(@"button被点击");}//不会有输出结果,因为button的事件被禁用。

BOOL selected;

当用户选中控件时,UIControl类会将其selected属性设置为YES。子类有时使用这个属性来让其选择自身,或者来表现不同的行为方式。

Layout method:

uicontrolcontentverticalalignment: Vertical Alignment

1.UIControlContentVerticalAlignmentCenter
2.UIControlContentVerticalAlignmentTop
3.UIControlContentVerticalAlignmentBottom
4.UIControlContentVerticalAlignmentFill

uicontrolcontenthorizontalalignment: Horizontal alignment

1.UIControlContentHorizontalAlignmentCenter
2.UIControlContentHorizontalAlignmentLeft
3.UIControlContentHorizontalAlignmentRight
4.UIControlContentHorizontalAlignmentFill

Uicontrol Introduction (ii)-(void) AddTarget: (ID) Target action: (SEL) Action forcontrolevents: (uicontrolevents) controlevents;

The Uicontrol class provides a standard mechanism for registering and receiving events. This specifies a method for the control to notify the agent when a particular event occurs. This method is used to register an event that can be combined with a logical or, so that multiple events can be specified in a separate addtarget call, and the following events are supported by the base class Uicontrol, and all controls are used unless otherwise noted:

Uicontroleventtouchdown

Single Touch press event: Triggers when the user touches the screen or a new finger falls
For example: [Button addtarget:self action: @selector (Onbutton) Forcontrolevents:uicontroleventtouchdown];

uicontroleventtouchdownrepeat

Multi-line Touch press event, touch count greater than 1: The user presses two fingers above the trigger

Uicontroleventtouchdraginside

When a touch is dragged within the control window

Uicontroleventtouchdraguotside

When a touch is dragged outside the control window

Uicontroleventtouchdragenter

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

Uicontroleventtouchexit

When you drag from inside the control window to the outside with a single touch

UIControlEventTouchUpInside

All touch lift events within the control

Uicontroleventtouchoutside

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, a faint touch because you put too many fingers to be canceled or locked up or interrupted by a phone call

uicontroleventtouchchanged

Sends a notification when the value of the control has changed. Controls for sliders, segmented controls, and other values

Uicontroleventeditingdidbegin

When you start editing in a text control, you send a notification

uicontroleventeditingchanged

Send notification when text of text control is changed

Uicontroleventeditingdidend

Send notification when text control is finished editing

Uicontroleventeditingdidoneit

Send notification when the edit is finished by pressing ENTER (or equivalent behavior) within the text control

uicontroleventeditingevents

Notifies all events about text editing

uicontroleventallevents

Notify All Events

Uicontrol Introduction (c)Common Methods-(void) Removetarget: (ID) Target action: (SEL) Action forcontrolevents: (uicontrolevents) controlevents;

Deletes the response action for one or more events, which can be removetarget using the Uicontrol class. Use the nil value to delete the target all actions for a given event:

when registering an event, there are two methods of signature:
    • -(void) Oneventmethod: (Uicontrol *) sender;
    • -(void) Oneventmethod;

OBJECTIVE-C: Reprint: Use of Uicontrol

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.