[英]Swift - How to change badge color of UITabItem programatically?
I want to change color of badge of barItem programatically from default red color.我想以编程方式从默认红色更改 barItem 徽章的颜色。
You need to modify it through UITabBar.appearance()需要通过 UITabBar.appearance() 修改
Example:例子:
struct ContentView: View {
var body: some View {
TabView {
SomeContent()
.tabItem {
Label("Tab1", systemImage: "star")
}
SomeContent()
.tabItem {
Label("Tab2", systemImage: "star")
}
.badge(10)
}
.onAppear() {
let appearance = UITabBarAppearance()
//portrait
appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .green
//landscape
appearance.inlineLayoutAppearance.normal.badgeBackgroundColor = .blue
UITabBar.appearance().standardAppearance = appearance
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.