UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

tint color

Forums > SwiftUI

I have a general question. In SwiftUI when presenting a sheet how do you get that sheet to accept the accent color of the previous view.

Does anyone know how to do this? Because what Im doing is now working.

Here is the view that I want the accent color to work on.

    var body: some View {
        HStack(alignment: .center) {
            Button(action: {
                // ACTION HERE
            }) {
                Image(systemName: "plus.circle.fill")
                    .font(.title)
            }.accentColor(Color("ChurchGreen"))

            HStack(alignment: .center) {
                Text("\(hymnData.songNum): ").foregroundColor(.gray)
                    .frame(width: 38, height: 30, alignment: .trailing)
                Text("\(hymnData.songName)")
                    .lineLimit(1)
            }
        }
    }

3      

Hello! I am not the real expert, but I solved this problem in my project in Xcode 12 (iOS 14) with defining accent color in the Assets folder. Here you can define an accent color for light and dark mode. than it will appear automatically wherever an accentcolor is used by the system. I hope it will work for you as well. Br, Martin

3      

Prior to Xcode 12, sheets did not inherit the Environment of their presenter so you had to set it separately.

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.