AlertViewController的自定義文字顏色
alertController有時有顯示的太單一吗蚌,我們需要給他自定義顏色布朦,這里我用的是NSMutableAttributedString囤萤,可以設(shè)置成自己喜歡的顏色和樣式。是趴。涛舍。
?UIAlertController *alert =[UIAlertController alertControllerWithTitle:@"立即支付" message:@"您的應(yīng)付金額為:¥58000" preferredStyle:UIAlertControllerStyleAlert];
? ? // 使用富文本來改變alert的title字體大小和顏色
? ? NSMutableAttributedString *title =[[NSMutableAttributedString alloc]initWithString:@"立即支付"];
? ? [title addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17]range:NSMakeRange(0,4)];
? ? [title addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]range:NSMakeRange(0,4)];
? ? [alert setValue:title forKey:@"attributedTitle"];
? ? // 使用富文本來改變alert的message字體大小和顏色
? ? // NSMakeRange(0, 14) 代表:從0位置開始 14個字符
? ? NSMutableAttributedString *message =[[NSMutableAttributedString alloc]initWithString:@"您的應(yīng)付金額為:¥58000"];
? ? [message addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16]range:NSMakeRange(0,14)];
? ? [message addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:250/255.0 green:84/255.0 blue:88/255.0 alpha:1.0]range:NSMakeRange(8,6)];
? ? [alert setValue:message forKey:@"attributedMessage"];
? ? UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"立即代付" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnullaction){
? ? ? ? [selfnowPay];
? ? }];
//? ? //設(shè)置按鈕的title顏色
? ? [cancelAction setValue:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]forKey:@"titleTextColor"];
//
//? ? //設(shè)置按鈕的title的對齊方式
? ? [cancelAction setValue:[NSNumber numberWithInteger:NSTextAlignmentCenter]forKey:@"titleTextAlignment"];
//
? ? UIAlertAction *okAction =[UIAlertAction actionWithTitle:@"朋友支付" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnullaction){
? ? ? ? [selffriendPay];
? ? }];
? ? // 設(shè)置按鈕的title顏色
? ? [okAction setValue:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]forKey:@"titleTextColor"];
//
//? ? //設(shè)置按鈕的title的對齊方式
? ? [okAction setValue:[NSNumber numberWithInteger:NSTextAlignmentCenter]forKey:@"titleTextAlignment"];
? ? [alert addAction:okAction];
? ? [alert addAction:cancelAction];
?? ?[selfpresentViewController:alert animated:YEScompletion:nil];
}
//朋友代付
-(void)friendPay{
}
//立即支付
-(void)nowPay{
}