IOS Custom System Uiactionsheet Modify the properties of the button

Source: Internet
Author: User
Tags uicontrol

The Uiactionsheet in iOS offers only a handful of styles in the SDK that basically meet the development requirements, but also encounter more cumbersome requirements, which require a separate custom uiactionsheet to modify the button's properties. If it is iOS4 or the previous version of the operation is more complex, but ios5 after the Uiactionsheet button replaced by UIButton type after easier, can directly facilitate all uiactionsheet Subview, Find the corresponding button can modify its properties, implementation is very simple, it should be noted that the button in the button list in the Uiactionsheet index ID can directly use the Tag property directly to obtain, it is very convenient to find them


Reference code;

The code is as follows Copy Code

-(void) Willpresentactionsheet: (Uiactionsheet *) Actionsheet {
if ([[[[[Uidevice Currentdevice] systemversion] floatvalue] > 4.9) {
For (UIView *view in actionsheet.subviews) {
if (View.tag = = 2) {
UIButton *button = (UIButton *) view;
Change the background
[Button Setbackgroundimage:[button backgroundimageforstate:uicontrolstatehighlighted] ForState: UIControlStateNormal];
Change color
[Button Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
BTN selection state, otherwise select unchanged background
[Button Setselected:yes];
} else {
}
}

} else {
IOS4 before the release button is not inherited from UIButton but Uithreepartbutton
For (UIView *view in actionsheet.subviews) {
if (View.tag = = 2) {
Uicontrol *btn = (Uicontrol *) view;
[Btn Setselected:yes];
} else {
}
}
}
}

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.