iOS之改變UIAlertViewController字型的顏色,uialertview字型顏色

來源:互聯網
上載者:User

iOS之改變UIAlertViewController字型的顏色,uialertview字型顏色

NSString *message = @"請確認資訊是否正確?";NSString *title = @"提示";UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];//改變title的大小和顏色NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:title];[titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, title.length)];[titleAtt addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, title.length)];[alertController setValue:titleAtt forKey:@"attributedTitle"];//改變message的大小和顏色NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:message];[messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, message.length)];[messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, message.length)];[alertController setValue:messageAtt forKey:@"attributedMessage"]; [self presentViewController:alertController animated:YES completion:nil];

上面的是修改UIAlertViewController的title和message字型的大小和顏色,採用的是修改attributedString其中的NSForegroundColorAttributeName顏色屬性和NSFontAttributeName字型大小屬性。UIAlertViewController中的標題的key:@"attributedTitle",標題中提示資訊的key:@"attributedMessage"。

UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:nil];[alertAction setValue:[UIColor purpleColor] forKey:@"_titleTextColor"];//    alertController.view.tintColor = [UIColor greenColor];[alertController addAction:alertAction];UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];/*取消按鈕的顏色*/[cancel setValue:[UIColor redColor] forKey:@"_titleTextColor"];[alertController addAction:cancel];

修改UIAlertViewController中修改所有按鈕的顏色使用下面這個方法:

alertController.view.tintColor = [UIColor greenColor];

修改單個UIAlertAction按鈕的字型顏色使用下面這個方法:

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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.