之前的程序做了一個可以輸入的消息彈出框预伺,樣式如下:
那么問題就來了,我現(xiàn)在想修改一下title曼尊、message酬诀、按鈕的字體大小和顏色,在網(wǎng)上查閱了一些資料骆撇,完成了修改瞒御。
使用KVC的方式:
UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"請修改輸入內(nèi)容"preferredStyle:UIAlertControllerStyleAlert];
[alertControlleraddTextFieldWithConfigurationHandler:^(UITextField*textField){
textField.placeholder=@"內(nèi)容";
//????????[textField?setFont:[UIFont?systemFontOfSize:16]];
}];
UIAlertAction*okAction?=?[UIAlertActionactionWithTitle:@"確定"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*action)?{
UITextField*login?=?alertController.textFields.firstObject;
}];
UIAlertAction*cancel?=?[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*action)?{
}];
/*title*/
NSMutableAttributedString*alertTitleStr?=?[[NSMutableAttributedStringalloc]initWithString:@"提示"];
[alertTitleStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:20]range:NSMakeRange(0,2)];
[alertTitleStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(0,2)];
[alertControllersetValue:alertTitleStrforKey:@"attributedTitle"];
/*message*/
NSMutableAttributedString*alertMessageStr?=?[[NSMutableAttributedStringalloc]initWithString:@"請修改輸入內(nèi)容"];
[alertMessageStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:18]range:NSMakeRange(0,7)];
[alertMessageStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColororangeColor]range:NSMakeRange(0,3)];
[alertMessageStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColorgreenColor]range:NSMakeRange(3,2)];
[alertMessageStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(5,2)];
[alertControllersetValue:alertMessageStrforKey:@"attributedMessage"];
/*取消按鈕的顏色*/
[cancelsetValue:[UIColorredColor]forKey:@"_titleTextColor"];
[alertControlleraddAction:cancel];
[alertControlleraddAction:okAction];
[selfpresentViewController:alertControlleranimated:YEScompletion:nil];