Change Text Color of Items in Uiactionsheet - iOS 8

Change Text Color of Items in UIActionSheet - iOS 8

There's an easy way if you still want to use UIActionSheet instead of UIAlertController in order to support older iOS versions.

UIActionSheet actually uses UIAlertController in iOS 8, and it has a private property _alertController.

SEL selector = NSSelectorFromString(@"_alertController");
if ([actionSheet respondsToSelector:selector])
{
UIAlertController *alertController = [actionSheet valueForKey:@"_alertController"];
if ([alertController isKindOfClass:[UIAlertController class]])
{
alertController.view.tintColor = [UIColor blueColor];
}
}
else
{
// use other methods for iOS 7 or older.
}

For Swift Below code should works

let alertAction = UIAlertAction(title: "XXX", style: .default) { (action) in

}

alertAction.setValue(UIColor.red, forKey: "titleTextColor")

Change text color in UIActionSheet buttons

iOS 8: UIActionSheet is deprecated. UIAlertController respects -[UIView tintColor], so this works:

alertController.view.tintColor = [UIColor redColor];

Better yet, set the whole window's tint color in your application delegate:

self.window.tintColor = [UIColor redColor];

iOS 7: In your action sheet delegate, implement -willPresentActionSheet: as follows:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
}
}

Change UIActionSheet buttons background color and button font

Basically what you are trying to do is something you should not do and should never have been doing. UIActionSheet and UIAlertController provide standard views with a very small number of variants and a completely standard appearance. You should not attempt to mess with that.

However, don't give up hope! Nothing stops you from devising your own view that looks however you want. And on iOS 8 (and iOS 7) this is very easy, because you are allowed to make a presented view controller whose view slides onto the screen and covers it only partially, just like an alert sheet. So go ahead and create your own non-standard column of buttons, rather than trying to modify Apple's standard.

Change text color in UIActionSheet buttons

iOS 8: UIActionSheet is deprecated. UIAlertController respects -[UIView tintColor], so this works:

alertController.view.tintColor = [UIColor redColor];

Better yet, set the whole window's tint color in your application delegate:

self.window.tintColor = [UIColor redColor];

iOS 7: In your action sheet delegate, implement -willPresentActionSheet: as follows:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
}
}

How to change font color on UIAlertController on particular action sheet?

Use .destructive instead of .default for the action style.

How to change Action Sheet Default action color only?

You cannot. Instead Change your method like below: Apple has provided red color for Destructive buttons.

refreshAlert.addAction(UIAlertAction(title: "Clear message history", style: .Destructive, handler: { (action: UIAlertAction!) in
print("Voila !! button color is changed")
}))

UIAlertAction change color

Refer following post:

Change Text Color of Items in UIActionSheet - iOS 8

Although it's related to changing color of UIActionSheet items but one user has answered according to change color of UIAlertAction items.



Related Topics



Leave a reply



Submit