SwiftUI|SwiftUI NavigationView设置导航条颜色
SwiftUI NavigationView设置导航条颜色
var body: some View {NavigationView {
List {
}
.navigationBarUIColor(ColorManager.mainColorBlue)}
extension View {func navigationBarUIColor(_ backgroundColor: Color?) -> some View {
self.modifier(NavigationBarModifier(backgroundColor: UIColor(backgroundColor!)))
}}
新建一个文件
//
//NavigationBarModifier.swift
//SwiftUI2
//
//Created by TongBin Mac on 2020/9/28.
//import SwiftUIstruct NavigationBarModifier: ViewModifier {var backgroundColor: UIColor?
var backColor: Color?init( backgroundColor: UIColor?) {
self.backgroundColor = backgroundColor
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.configureWithTransparentBackground()
coloredAppearance.backgroundColor = .clear
coloredAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
coloredAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().compactAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
UINavigationBar.appearance().tintColor = .white}func body(content: Content) -> some View {
ZStack{
content
VStack {
GeometryReader { geometry in
Color(self.backgroundColor ?? .clear)
.frame(height: geometry.safeAreaInsets.top)
.edgesIgnoringSafeArea(.top)
Spacer()
}
}
}
}
}
【SwiftUI|SwiftUI NavigationView设置导航条颜色】optinon + commond + P 看一下效果
文章图片
image.png ps 对于网上这个功能也收费,表示不明白为什么
推荐阅读
- 第6.2章(设置属性)
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- 15、IDEA学习系列之其他设置(生成javadoc、缓存和索引的清理等)
- performSelectorOnMainThread:withObject:waitUntilDone:参数设置为NO或YES的区别
- SwiftUI|SwiftUI iOS 瀑布流组件之仿CollectionView不规则图文混合(教程含源码)
- spring|spring boot中设置异步请求默认使用的线程池
- Python绘制小红花
- day|day 28 设置路由表
- Flutter|Flutter SwiftUI React 对比
- flutter设置沉浸式状态栏