1

As in iOS8 UIAlertView is deprecated.we should use UIAlertController. I want to customize it like font color, font family of message label of alertcontrller's view, also change background color of ok button.i don't know the right way to do that.

Please Help!!

Any help will be appreciable!!

Bhumit Mehta
  • 16,278
  • 11
  • 50
  • 64
Tanvi Jain
  • 917
  • 2
  • 7
  • 19

2 Answers2

2

I think, you have been perform task with them. But I think it's useful for someone.

Below code is working perfectly with my requirements. Please do changes according to your requirements.

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *setCoverPhoto = [UIAlertAction
                                actionWithTitle:@"First Button"
                                style:UIAlertActionStyleDefault
                                handler:^(UIAlertAction *action){

                                    NSLog(@"First Button");

                                }];
[alertController addAction:setCoverPhoto];


UIAlertAction *deleteImageAct = [UIAlertAction
                                 actionWithTitle:@"Second Button"
                                 style:UIAlertActionStyleDefault
                                 handler:^(UIAlertAction *action) {

                                     NSLog(@"Second Button");

                                 }];
[alertController addAction:deleteImageAct];

UIAlertAction *setImageASNotif = [UIAlertAction
                                  actionWithTitle:@"Third Button"
                                  style:UIAlertActionStyleDefault
                                  handler:^(UIAlertAction *action) {

                                      NSLog(@"Third Button");

                                  }];
[alertController addAction:setImageASNotif];


alertController.view.tintColor = [UIColor whiteColor];

UIView *subView = alertController.view.subviews.firstObject;
UIView *alertContentView = subView.subviews.firstObject;
[alertContentView setBackgroundColor:[UIColor darkGrayColor]];

alertContentView.layer.cornerRadius = 5;

[self presentViewController:alertController animated:YES completion:nil];
Renish Dadhaniya
  • 10,642
  • 2
  • 31
  • 56
1

Pretty darn good tutorial over at Matt Thompson's site:

http://nshipster.com/uialertcontroller/

Also, how to configure the alert on the iOS Developer Library:

https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UIAlertController_class/index.html

Steve Rosenberg
  • 19,348
  • 7
  • 46
  • 53
  • Thanks @Steve Rosenberg.but can u give me link for Objective-C too. – Tanvi Jain Oct 08 '14 at 05:07
  • http://pivotallabs.com/uialertcontroller-ios-8/ of course the apple site is in Obj C and Swift – Steve Rosenberg Oct 08 '14 at 05:09
  • this will not change the background color of OK button – gabbler Oct 08 '14 at 05:12
  • tintcolor discussed here: http://stackoverflow.com/questions/25795065/ios-8-uiactivityviewcontroller-and-uialertcontroller-button-text-color-uses-wind – Steve Rosenberg Oct 08 '14 at 05:16
  • @ CarouselMin is there any way to change the background color of ok button? – Tanvi Jain Oct 08 '14 at 05:18
  • This does not answer the OP's question of how to configure the appearance of the alert view. – phatmann May 07 '15 at 16:35
  • Down voted for two reasons: 1. This is essentially a link only answer. There is no good information in the answer without those links. 2. Neither of these links provide information on *customising* the controller as per the question: `I want to customize it like font color, font family` – James Webster Oct 08 '15 at 15:57