iOS8 after the Uialertcontroller

Source: Internet
Author: User

Yesterday the project needs to Uiactionsheet the color of the font system blue, so go online to find ways.

The method is simple and iterates through the child controls in the Uiactionsheet. Of course this is the method before iOS8, why say so, wait for you to know, first talk about iOS8 before the call.

before IOS8

Create a uiactionsheet

            Uiactionsheet *t_actionsheet = [[Uiactionsheet alloc]initwithtitle:nil delegate:self cancelButtonTitle:@ ' Cancel ' destructivebuttontitle:@ "Dial" otherbuttontitles:@ "Send SMS", @ "Copy business Card", Nil];            T_actionsheet.actionsheetstyle = Uiactionsheetstyleblackopaque;            [T_actionsheet ShowInView:self.view];


Called when a button is clicked. The view'll be automatically dismissed after this call returns

-() Actionsheet: (uiactionsheet  *) actionsheet Clickedbuttonatindex: (nsinteger ) Buttonindex;

-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (nsinteger) buttonindex{    if (ButtonIndex = = 0) {        [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:[nsstring stringwithformat:@ "tel://%@", _ MAR_NUM[_SELECTROW][1]];    else if (Buttonindex = = 1) {        [[uiapplication Sharedapplication]openurl:[nsurl urlwithstring:[nsstring stringwithformat:@ "sms://%@", _mar_num[_selectrow][1]] [];    } else if (Buttonindex = = 2) {        Uipasteboard *pasteboard = [Uipasteboard Generalpasteboard];        pasteboard.string = [NSString stringwithformat:@ "%@:%@", _mar_num[_selectrow][2],_mar_num[_selectrow][1]];}    }


-(void) Willpresentactionsheet: (uiactionsheet *) Actionsheet; //Before animation and showing view

-(void) Willpresentactionsheet: (Uiactionsheet *) actionsheet{for    (id subviwe in actionsheet.subviews) {        if ([ Subviwe Iskindofclass:[uibutton class]) {            UIButton *button = (uibutton*) subviwe;            [Button Settitlecolor:[uicolor colorwithred:0 green:0.478431 blue:1 alpha:1] forstate:uicontrolstatenormal];}}    }

After the breakpoint is assigned,


you can clearly see that there are 5 sub-views in the upcoming Uiactionsheet, of which 4 buttons are added for myself (the No. 0 may be the background color bar, have not been tried) and then you can look at the code and assign it to a UIButton change the properties again.

When you are equal, two buttons actually occupy the same pointer, so you can change the properties of the buttons. Of course you can also change properties directly with Subview (Uialertbutton).


After that, you can change the color in the font.

after IOS8after IOS8, uiactionsheet became Uialertcontroller, and that's what the authorities say.
a Uialertcontroller object displays a warning message to the user. This class replaces the uiactionsheet and uialertview classes to display alerts. withAction andthe style you wantConfigurationAlertsafter the controller,currentlyused byPresentviewcontroller:Animation:Complete:Method. (now it's a controller that distinguishes it from the previousNs_class_available_ios(8_0)@interfaceUialertcontroller:Uiviewcontroller previous :Ns_class_available_ios(2_0)@interfaceUiactionsheet:UIView )
after iOS8 you need to create, of course, you use the previous method created in the iOS8 can also be displayed, click and so on, but some methods are useless, such as the method of modifying fonts in this article, because it is no longer UIView but Uiviewcontroller, and to note that, when you use the following iOS8 after the creation of the method, running on the iOS8 machine, the agent will not be executed, do not know right, but I ran the top two agent method did not execute ...

Important: uiactionsheet in iOS 8 disapproved. ( Note, uiactionsheet Delegate is also obsolete . ) to create and manage action slices on iOS  8 after , use instead uialertcontroller and Preferredstyle of uialertcontroller Styleactionsheet .

before the target version of iOS to iOS 8 for the application, use uiactionsheet The class displays a set of choices to the user on how to perform a given task. You can also use action slices to prompt users to identify potentially dangerous actions. action slice contains an optional title and one or more Buttons , each of the corresponds to the Action taken .

use the properties and methods of the class to configure the action slice message, style, and previous submit button. You should also designate an action movie that represents you. your entrusted object is responsible for executing the action with any button when they are tapped and should conform to the Uiactionsheetdelegate protocol. for More information about how to implement a delegate , see uiactionsheetdelegate Protocol reference .


 Uialertcontroller *alertctrl = [Uialertcontroller alertcontrollerwithtitle:nil m            Essage:nil Preferredstyle:uialertcontrollerstyleactionsheet]; [Alertctrl addaction:[uialertaction actionwithtitle:@ "Cancel" style:u                                                            Ialertactionstylecancel handler:^ (uialertaction *action) { Code}]];

[ self presentviewcontroller: Alertctrl animated:YES completion:nil];

Or you can
    Uialertcontroller *alertcontroller = [Uialertcontroller alertcontrollerwithtitle:title message:message Preferredstyle:uialertcontrollerstylealert];        Create the actions.    Uialertaction *cancelaction = [Uialertaction actionwithtitle:cancelbuttontitle style:uialertactionstylecancel handler:^ (uialertaction *action) {        NSLog (@ "the \" okay/cancel\ "alert ' s Cancel action occured.");    }];
[Alertcontroller addaction:cancelaction];  [Self Presentviewcontroller:alertcontroller animated:yes completion:nil];

which, several attributes needless to say you should also know

typedef Ns_enum (Nsinteger, Uialertcontrollerstyle) {

Uialertcontrollerstyleactionsheet = 0,

Uialertcontrollerstylealert

} Ns_enum_available_ios(8_0);


typedef Ns_enum (Nsinteger, Uialertactionstyle) {

Uialertactionstyledefault = 0,

Uialertactionstylecancel,

Uialertactionstyledestructive

} Ns_enum_available_ios(8_0);


here, how to modify the color font I think it might be Uialertcontroller this method.

-(void) Addtextfieldwithconfigurationhandler: (void (^) (Uitextfield *textfield)) Configurationhandler;

Here I directly use the uialertactionstyledestructive To change one of the items into a uialert red, so there is no real custom color, but to understand the estimate can be, or quite simple.

iOS8 after the Uialertcontroller

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.