gpt4 book ai didi

swiftui - 更改导航标题文本颜色 SwiftUI

转载 作者:行者123 更新时间:2023-12-03 23:27:02 28 4
gpt4 key购买 nike

我已经查看并尝试了所有不同的组合,但我无法弄清楚如何更改 View 导航栏标题的文本颜色。这是我的代码,我也在尝试使用我已经从我的 Assets 文件夹中添加和使用的自定义颜色。我知道这个问题已被问过多次,但实际上我尝试的所有方法都不起作用。顺便说一句,我在 Xcode 11.6 beta1 上。

import SwiftUI
import Firebase

struct MyProfileView: View {

let navBarAppearance = UINavigationBar.appearance()


var body: some View {

NavigationView {

// Design the View Here
VStack {

//Profile Picture + Info
VStack(alignment: .leading) {

//Profile Picture + Info
HStack(alignment: .bottom, spacing: 15) {

// Profile Picture
Image("PROFILEPICTURE")
.clipShape(Rectangle())
.cornerRadius(100)
.frame(width: 90, height: 90)
.shadow(color: Color.black.opacity(0.3), radius: 1, x: 1, y: 1)

//Username + Zone
VStack(alignment: .leading, spacing: 3) {

Text("Gardn.")
.font(.system(size: 20, weight: .semibold))
.foregroundColor(Color("ShipsOfficer"))

Text("Zone 9, Gold Base")
.font(.system(size: 14, weight: .light))
.foregroundColor(Color("ShipsOfficer").opacity(0.4))
}



Spacer()
}

}

.padding(.leading,30)

// Deco line under info
Rectangle()
.frame(width: 30, height: 2)
.foregroundColor(Color("ShipsOfficer").opacity(0.1)).cornerRadius(100)
.padding(.top,10)

Spacer()

}


.navigationBarHidden(false)
.navigationBarTitle(Text("My Profile"))

.navigationBarItems(trailing:

// Navigation Button
NavigationLink(destination: SettingsView()) {

Image(systemName: "slider.horizontal.3")
.frame(width: 25, height: 25)
.padding()
.font(.title)
.foregroundColor(Color("Freshness"))
}

)

}

}
func customNavBarTitle() {

navBarAppearance.largeTitleTextAttributes = [
.foregroundColor : UIColor.Color("ShipsOfficer),
]

}

}

最佳答案

You can do it with init()

init() {
//Use this if NavigationBarTitle is with Large Font
UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.red]

//Use this if NavigationBarTitle is with displayMode = .inline
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.red]
}
完整代码
struct YourView: View {

init() {
//Use this if NavigationBarTitle is with Large Font
UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.red]

//Use this if NavigationBarTitle is with displayMode = .inline
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.red]
}

var body: some View {

NavigationView {
List{
Text("1")
}
}
.navigationBarTitle("TEST")

}
}
}

关于swiftui - 更改导航标题文本颜色 SwiftUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62420299/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com