Mic*_*air 17 back-button swiftui
当您单击该按钮时,它会将您带到一个新视图并在左上角放置一个后退按钮。我不知道是什么属性控制了后退按钮的颜色。我尝试添加一个重音颜色和前景颜色,但它们只编辑视图内的项目。
var body: some View {
NavigationView {
NavigationLink(destination: ResetPasswordView()) {
Text("Reset Password")
.foregroundColor(Color(red: 0, green: 116 / 255, blue: 217 / 255))
.padding()
}
}
}
Run Code Online (Sandbox Code Playgroud)
tur*_*ted 45
您可以使用accentColorNavigationView 上的属性来设置后退按钮颜色,如下例所示:
var body: some View {
NavigationView {
List(1..<13) { item in
NavigationLink(destination: Text("\(item) x 8 = \(item*8)")) {
Text(String(item))
}
}.navigationBarTitle("Table of 8")
}.accentColor( .black) // <- note that it's added here and not on the List like navigationBarTitle()
}
Run Code Online (Sandbox Code Playgroud)
mgy*_*yky 13
在资产目录 (Assets.xcassets) 中添加AccentColor设置。Xcode 应用您在此颜色集中指定的颜色作为您的 app\xe2\x80\x99s 强调色。
\n将强调色添加到资产目录后,导航栏后退按钮将变为该颜色。这就是您所需要的。
\n如果您的应用没有\xe2\x80\x99t 有 AccentColor 颜色集,请通过下面列出的步骤手动创建颜色集:
\n默认情况下,强调色适用于应用程序中使用色调颜色的所有视图和控件,除非您覆盖视图层次结构的特定子集的颜色。但是,您可能希望将强调色合并到用户界面中不\xe2\x80\x99 不依赖色调颜色的其他部分,例如静态文本元素。\n要在代码中使用资产目录中的强调色值,像这样加载颜色:
\nText("Accent Color")\n .foregroundStyle(Color.accentColor)\nRun Code Online (Sandbox Code Playgroud)\nlabel.textColor = UIColor.tintColor\nRun Code Online (Sandbox Code Playgroud)\n强调色或色调颜色是一种广泛的主题颜色,适用于应用程序中的视图和控件。使用强调色快速为您的应用创建统一的配色方案。您可以通过在资产目录中指定强调色来为应用程序设置强调色。
\n\n有关该主题的更多信息请查看文档。
\n小智 8
我怀疑这是正确的方法,但我通过修改 SceneDelegate.swift 来设置窗口色调颜色来让它工作。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use a UIHostingController as window root view controller
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: ContentView())
window.tintColor = .green // set the colour of the back navigation text
self.window = window
window.makeKeyAndVisible()
}
Run Code Online (Sandbox Code Playgroud)
将 .accentColor 修饰符添加到 NavigationView ,如下所示
NavigationView {
Text("Hello World")
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Close") { }
}
}
}
.accentColor(.themeColor)
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 XCode 12,请考虑在Assets.xcassets. XCode 将为应用程序中的所有导航后退按钮使用此颜色。
请注意,这也会影响其他 UI 元素。其中之一是按钮。您始终可以使用accentColor修饰符来覆盖它:
Button("Button With Different Accent Color") {
// do something useful
}
.accentColor(.red)
Run Code Online (Sandbox Code Playgroud)
我试图做同样的事情有一段时间了,但认为还没有 SwiftUI 解决方案。可以完成工作的一件事(如果它适用于您的用例)是 UIKit 的外观:
UINavigationBar.appearance().tintColor = .black
| 归档时间: |
|
| 查看次数: |
8608 次 |
| 最近记录: |