Luko
(Luciano Schillagi)
1
Hello Community!
I want to change the color of the items in the ActionSheet (SwiftUI)
For instance:
To change the "blue" default color to orange.
Is it possible? Suggestions?
Thanks
Lucey120
(Lucey)
2
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")
Luko
(Luciano Schillagi)
3
Great, thanks a lot @Lucey120
Luko
(Luciano Schillagi)
4
Another solution:
Adds this line in the AppDelegate.swift file:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor(named: "Orange")
}