如何将状态栏背景颜色更改为不同的颜色。我正在使用 NavigationView 和 ZStack。
例如,我希望绿色导航栏上方的白色区域为绿色。我怎样才能改变它?
我试过的
这是我的 NavigationBar 代码:
init() {
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor : UIColor(#colorLiteral(red: 0.8745098039, green: 0.3411764706, blue: 0, alpha: 1))]
UINavigationBar.appearance().backgroundColor = UIColor(named: "backgroundColor")
}
Run Code Online (Sandbox Code Playgroud)
这是我的应用程序背景颜色代码:
var body: some View {
NavigationView {
ZStack {
Color("backgroundColor")
.edgesIgnoringSafeArea(.all)
}
.navigationBarTitle(Text("Agenda"))
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后但并非最不重要的是我的场景委托代码:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let newAppearance = UINavigationBarAppearance()
newAppearance.configureWithOpaqueBackground()
newAppearance.backgroundColor = .black
newAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().standardAppearance = newAppearance
//Other code for displaying the first screen
}
Run Code Online (Sandbox Code Playgroud)
试试这行代码
import SwiftUI
struct ContentView: View {
@State private var selection = 0
var body: some View {
ZStack(alignment: .top) {
VStack() {
Rectangle()
.foregroundColor(.orange)
.edgesIgnoringSafeArea(.top)
.frame(height: 0)
TabView {
AgendaView().tabItem({
Image(systemName: Constants.TabBarImageName.tabBar0 )
Text("\(Constants.TabBarText.tabBar0)")
}).tag(0)
StandView().tabItem({
Image(systemName: Constants.TabBarImageName.tabBar1 )
Text("\(Constants.TabBarText.tabBar1)")
}).tag(1)
UitslagenView().tabItem({
Image(systemName: Constants.TabBarImageName.tabBar2 )
Text("\(Constants.TabBarText.tabBar2)")
}).tag(2)
NieuwsView().tabItem({
Image(systemName: Constants.TabBarImageName.tabBar3 )
Text("\(Constants.TabBarText.tabBar3)")
}).tag(3)
InstellingenView().tabItem({
Image(systemName: Constants.TabBarImageName.tabBar4 )
Text("\(Constants.TabBarText.tabBar4)")
}).tag(4)
}.accentColor(Color(#colorLiteral(red: 0.8745098039, green: 0.3411764706, blue: 0.06666666667, alpha: 1)))
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3693 次 |
| 最近记录: |