Switch button for iOS base control (uiswitch)

Source: Internet
Author: User
UISwitch控件是iOS开发的基础控件,是非常简单的一个控件,因为它的方法比较少。UISwitch继承于UIControl基类,因此可以当成活动控件使用。

Note: The switch state is read by its on property, which is a bool property
Create:
uiswitch* myswitch = [[Uiswitch alloc]initwithframe:cgrectmake (0, 150.0f,100.0f,0.0f,0.0f)];
Maybe you wonder why it's size is set to 0? Yes, it's size you set is not valid, the system will assign you the size.
Show:
[Self.view Addsubview:myswitch];
To get the switch status:
BOOL Switchstate=myswitch.on;
Listener events:
[Myswitch addtarget:self Action: @selector (switchvaluechanged:) forcontrolevents:uicontroleventvaluechanged];
-(void) switchvaluechanged: (ID) sender{
if ([Myswitch.on]==yes)
{
Handling Events
}
Else
{//Handling events
}
}

Switch button for iOS base control (uiswitch)

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.