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
"Untrusted App Developer" Message When Installing Enterprise iOS Application
Didreceiveremotenotification Not Working in the Background
Date to Milliseconds and Back to Date in Swift
How to Create Negative Firebase Timestamp in Swift
Firebase Cloud Messaging - Check Existing or Available Topics
How to Manually Deprecate Members
Using Audiobufferlist with Swift
Passing Data to View Controllers That Are Embedded in Container Views
iOS Nsdate() Returns Incorrect Time
Filemanager Cannot Find Audio File
Error: Initializer for Conditional Binding Must Have Optional Type, Not 'String'
How Does Apple Notify iOS Apps of Refunds of In-App Purchases (Iap)
How to Get Rgb Values from Uicolor
How to Send a Silent Push Notification Payload
Posting JSON Data Using Afnetworking 2.0
Does @Synchronized Guarantees for Thread Safety or Not
How to Add Equal Spacing and Equal Width for Button in iOS Auto Layout