Alert修改字体颜色和字体

  NSString*str =@"你的手机xxx还未绑定,只有绑定才能进行相关操作,是否绑定";

   NSString*title =@"提示";

   UIAlertController*alertC= [UIAlertControlleralertControllerWithTitle:titlemessage:strpreferredStyle:UIAlertControllerStyleAlert];


   //修改title

   NSMutableAttributedString*alertControllerStr = [[NSMutableAttributedStringalloc] initWithString:title];

    

    [alertControllerStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(0,2)];

    

    [alertControllerStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:17]range:NSMakeRange(0,2)];

    

    [alertCsetValue:alertControllerStrforKey:@"attributedTitle"];


    

   //改变alert提示内容的字体和颜色

   NSMutableAttributedString*alertControllerMessageStr = [[NSMutableAttributedStringalloc] initWithString:str];

    

    [alertControllerMessageStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColorgreenColor]range:NSMakeRange(0,20)];

    

    [alertControllerMessageStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:15]range:NSMakeRange(0,20)];

    

    [alertCsetValue:alertControllerMessageStrforKey:@"attributedMessage"];

    

    

    

    

    

   UIAlertAction*cancel = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction*_Nonnullaction) {

        

    }];

    

    //改变按钮的颜色

    [cancelsetValue:[UIColorcolorWithRed:24/255.0green:242/255.0blue:207/255.0alpha:1]forKey:@"titleTextColor"];

    

    [alertCaddAction:cancel];

   UIAlertAction*yes = [UIAlertActionactionWithTitle:@"确认"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {

        

    }];

    [yessetValue:[UIColorcolorWithRed:24/255.0green:242/255.0blue:207/255.0alpha:1]forKey:@"titleTextColor"];


    [alertCaddAction:yes];

    

    [selfpresentViewController:alertCanimated:YEScompletion:nil];



版权声明:本文为qq_34353990原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。