IOS changes the color of the UIAlertViewController font and uialertview font

Source: Internet
Author: User

IOS changes the color of the UIAlertViewController font and uialertview font

NSString * message = @ "are you sure the information is correct? "; NSString * title = @" prompt "; UIAlertController * alertController = [UIAlertController alertControllerWithTitle: title message: message preferredStyle: UIAlertControllerStyleActionSheet]; // change the title size and color. Optional * titleAtt = [[NSMutableAttributedString alloc] initWithString: title]; [titleAtt addattriatt: NSFontAttributeName value: [UIFont systemFontOfSize: 16] range: NSMakeRange (0, title. length)]; [titleAtt addattriatt: NSForegroundColorAttributeName value: [UIColor orangeColor] range: NSMakeRange (0, title. length)]; [alertController setValue: titleAtt forKey: @ "attributedTitle"]; // change the message size and color NSMutableAttributedString * messageAtt = [[NSMutableAttributedString alloc] initWithString: message]; [messageAtt addattriatt: NSFontAttributeName value: [UIFont systemFontOfSize: 13] range: NSMakeRange (0, message. length)]; [messageAtt addattriatt: NSForegroundColorAttributeName value: [UIColor yellowColor] range: NSMakeRange (0, message. length)]; [alertController setValue: messageAtt forKey: @ "attributedMessage"]; [self presentViewController: alertController animated: YES completion: nil];

The preceding figure shows how to modify the title and message font color of UIAlertViewController, and how to modify the NSForegroundColorAttributeName color attribute and NSFontAttributeName font size attribute of attributedString. Key of the title in UIAlertViewController: @ "attributedTitle", key of the message prompted in the title: @ "attributedMessage ".

UIAlertAction * alertAction = [UIAlertAction actionWithTitle: @ "style" style: incluhandler: nil]; [alertAction setValue: [UIColor purpleColor] forKey: @ "_ titleTextColor"]; // alertController. view. tintColor = [UIColor greenColor]; [alertController addAction: alertAction]; UIAlertAction * cancel = [UIAlertAction actionWithTitle: @ "cancel" style: UIAlertActionStyleCancel handler: nil]; /* color of the cancel button */[cancel setValue: [UIColor redColor] forKey: @ "_ titleTextColor"]; [alertController addAction: cancel];

Modify the color of all buttons in UIAlertViewController using the following method:

alertController.view.tintColor = [UIColor greenColor];

Use the following method to modify the font color of a single UIAlertAction button:

[cancel setValue:[UIColor redColor] forKey:@"_titleTextColor"];

 

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.