简体   繁体   中英

Setting text and button color for Alert component in SwiftUI?

It might not be a great idea to set text color in Alert but I would love to know if the possibility is there.

How to set text and button text color for the Alert component in SwiftUI. Tried the code below but the color set seems to be ignored by the library.

.alert(isPresented: $showingTrackingAlert) {
    Alert(
        title: Text("TITLE").foregroundColor(.red),
        message: Text("MESSAGE TEXT").foregroundColor(.red),
        primaryButton: .destructive(Text("DELETE").foregroundColor(.red)),
        secondaryButton: .cancel(Text("CANCEL").foregroundColor(.red))
    )
}

REFERECE

How to change UIAlertView text color?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM