我有一个 UIAlertController 和一堆 UIAlertAcion 按钮。现在我需要用其他颜色而不是相同颜色显示一个按钮。
对于前
按钮1
按钮2
按钮 3
Button1 和 button3 应该是蓝色的
和
button2 应该是红色的。
可能吗 ?如何?
只是抛出你的想法......
我的代码:
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Food Menu" message:@"Select the MenuItem" preferredStyle:UIAlertControllerStyleActionSheet];
for(int i= 0; i<[menus count];i++){
UIAlertAction *action = [UIAlertAction actionWithTitle:[menu objectAtIndex:i] style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
[actionSheet dismissViewControllerAnimated:YES completion:nil];
//do SomeWork
}];
if(i==currentIndex){
//Put button Color Red
}
else{
//put button color Blue
}
[actionSheet addAction:action];
}
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction* action){
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];
[actionSheet addAction:cancel];
[self presentViewController:actionSheet animated:YES completion:nil];
}