IOS 修改UIAlertController的按鈕標題的字體顏色,字號,內容


 

IOS 修改UIAlertController的按鈕標題的字體顏色,字號,內容

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    
    //修改標題的內容,字號,顏色。使用的key值是“attributedTitle”
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc] initWithString:@"請選擇創建商機或者創建項目"];
    [AttributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, [[AttributedStr string] length])];
    [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, [[AttributedStr string] length])];
    [alertVC setValue:AttributedStr forKey:@"attributedTitle"];
    
  
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"創建項目" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self loadCtrlWithTypeStr:@"1"];
    }];
    
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"創建商機" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self loadCtrlWithTypeStr:@"2"];
    }];
    
    
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [action1 setValue:[UIColor darkGrayColor] forKey:@"_titleTextColor"];
    [action2 setValue:[UIColor darkGrayColor] forKey:@"_titleTextColor"];
    [action3 setValue:[UIColor darkGrayColor] forKey:@"_titleTextColor"];

    
    [alertVC addAction:action1];
    [alertVC addAction:action2];
    [alertVC addAction:action3];
    [self presentViewController:alertVC animated:YES completion:nil];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM