我想創建一個具有操作表樣式的UIAlertController,但我想將背景顏色更改爲灰色。我已經能夠找到一種方法來改變UIAlertController的背景顏色,但不是取消按鈕。取消按鈕是單獨的,保持白色。UIAlertController更改操作表的取消按鈕的背景顏色
這是我現在所擁有的代碼:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Option 1" style:UIAlertActionStyleDefault handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Option 2" style:UIAlertActionStyleDefault handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Option 3" style:UIAlertActionStyleDefault handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
UIView *firstSubview = alert.view.subviews.firstObject;
UIView *alertContentView = firstSubview.subviews.firstObject;
for (UIView *subSubView in alertContentView.subviews) {
subSubView.backgroundColor = [UIColor darkGrayColor]; // Here you change background
}
alert.view.tintColor = [UIColor whiteColor];
[self.controller presentViewController:alert animated:YES completion:nil];
這使我有以下結果: Link
我曾參觀過How to change the background color of the UIAlertController? 但沒有任何解決方案都爲自定義顏色取消按鈕的背景。
任何幫助,將不勝感激!
是否要更改取消按鈕的背景顏色? – user3182143
查看我的編碼我將取消按鈕顏色更改爲darkGray顏色。 – user3182143
我希望取消按鈕具有深灰色背景色和白色文本。你的代碼似乎沒有這樣做,但是相反:你的取消按鈕的背景顏色是白色的,而你的文本顏色是灰色的 – Pibomb