Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change text color of actionSheet in SwiftUI

Tags:

swift

swiftui

I am trying to change color of actionSheet's text in SwiftUI. Unable to do so. I tried following code

    private var actionSheet: ActionSheet {
    let button1 = ActionSheet.Button.default(Text("Week 1").foregroundColor(.orange)) {
        self.selectedShuffleWeek = "Week 1"
        self.shufflePresented = true
        self.actionSheetPresented = false
    }
    let button2 = ActionSheet.Button.default(Text("Week 2").foregroundColor(Color("GreenColor"))) {
        self.selectedShuffleWeek = "Week 2"
        self.shufflePresented = true
        self.actionSheetPresented = false
    }
    let button3 = ActionSheet.Button.default(Text("Week 3").foregroundColor(Color("GreenColor"))) {
        self.selectedShuffleWeek = "Week 3"
        self.shufflePresented = true
        self.actionSheetPresented = false
    }
    let dismissButton = ActionSheet.Button.cancel {
        self.selectedShuffleWeek = ""
        self.actionSheetPresented = false
    }


    let buttons = [button1, button2, button3, dismissButton]
    return ActionSheet(title: Text("Shuffle"),
                       buttons: buttons)
}

After that I also tried to change the accent color of the view in which I am showing this action sheet but its not working.

like image 594
Lalli Avatar asked Aug 04 '19 14:08

Lalli


1 Answers

I've managed to get this working by adding the following code in SceneDelegate inside func scene(_...

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = Color("GreenColor")

This will change the accent colour of all ActionSheets in your application.

like image 89
Gian Avatar answered Oct 21 '22 14:10

Gian