ios - SwiftUI の TabView の色をカスタム色に変更できない

okwaves2024-01-25  7

これが私の TabView です:

struct HomeView: View {
    let auth: UserAuth
    init(auth: UserAuth) {
        self.auth = auth
        UITabBar.appearance().barTintColor = UIColor(named: "CustomOrange")
        UITabBar.appearance().unselectedItemTintColor = UIColor.white.withAlphaComponent(0.6)
        UITabBar.appearance().autoresizesSubviews = true
        UITabBar.appearance().backgroundColor = UIColor(named: "CustomOrange")
    }
    
    var body: some View {
        ZStack {
                TabView(selection: $selectedTab) {
                    Settings(auth: auth)
                    .tabItem {
                        Image(systemName: "gear")
                        Text("Settings")
                    }.tag(0)

タブビュー バーの色をカスタム オレンジに設定した場合:

UITabBar.Appearance().barTintColor = UIColor(名前: "CustomOrange")

常にデフォルトのシステムオレンジ (Color.orange と同等) になります

私のカスタム オレンジは #ff8000 です。

タブバーの色はシステムカラーに制限されていますか?



------------------------

Xcode 12 / iOS 14 では正常に動作します。これは、色合い (純粋ではない) の色です (結果をテストするためにピッカーを使用した場合)。純粋な色を割り当てるには、半透明を無効にする必要があります

    UITabBar.appearance().isTranslucent = false

0

総合生活情報サイト - OKWAVES
総合生活情報サイト - OKWAVES
生活総合情報サイトokwaves(オールアバウト)。その道のプロ(専門家)が、日常生活をより豊かに快適にするノウハウから業界の最新動向、読み物コラムまで、多彩なコンテンツを発信。