How to Change Text Color of Actionsheet in Swiftui

SwiftUI ActionSheet how can i change cancel color

No explicit way, but as workaround you can just use destructive style for explicitly named cancel button with nop action, like

.actionSheet(isPresented: $showLocationOptions) {
ActionSheet(title: Text("Which city/town is this place in ?"), message: Text("Select a location"), buttons: [

.default(Text(location1)) { },
.default(Text(location2)) { },
.default(Text(location3)) { },
.default(Text(location4)) { },
.default(Text(location5)) { },
.destructive(Text("Cancel")){ // << keep as last
// just nop - will be just closed
}
])
}

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];
}
}
}

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

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

Setting text and button color for Alert component in SwiftUI?

The main goal was to set the cancel button text so a workaround we ended up with is to set a global tint color inside

func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) {}

with the following code

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor(named: "secondaryColorDefinedInAssets")



Related Topics



Leave a reply



Submit