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
Nsbutton Background Transparent After Getting Focus
Firebase Crashlytics Not Showing Crash Report in Console Dashboard Swift
Core Image Filter Cisourceovercompositing Not Appearing as Expected with Alpha Overlay
How to Import Googleanalytics Header into a Library Framework
Class with Non-Optional Property Conforming to Protocol with Optional Property
Menuapp in Swift 4 to Run on Login for High Sierra
How to Set Avaudioengine Input and Output Devices (Swift/Macos)
Swiftui Classes That Conforms Observableobject Should Be Singleton
How to Create a Hotspot Network in iOS App Using Swift
How to 'Addtarget' to Uilabel in Swift
Swift: Differencebetween a Typealias and an Associatedtype with a Value in a Protocol
How to Sort Dates in a Dictionary
Swiftui - How to Get Coordinate/Position of Clicked Button
Metal Kernels Not Behaving Properly on the New MACbook Pro (Late 2016) Gpus