改變系統自帶alertView的樣式

首先,我變動的是系統的UIAlertController,而UIAlertView也有對應的方法能改變樣式,這裏就不列舉了。

方法比較簡單,就不深入介紹了,主要運用的是KVC方法。

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *confirmButton = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil];
[cancelButton setValue:k333333Color forKey:@"titleTextColor"];
[alertController addAction:cancelButton];
[alertController addAction:confirmButton];
[self presentViewController:alertController animated:YES completion:nil];

就可以設置對應的按鈕顏色。

值得一提的是,這個alertController只允許設置一個樣式爲cancel的按鈕,會自動排布在最左邊。當你設置多於1個的時候,會報錯。這一點千萬記得。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章