这是我的TabView
:
struct HomeView: View {
let auth: UserAuth
init(auth: UserAuth) {
self.auth = auth
UITabBar.appearance().barTintColor = UIColor(named: "CustomOrange")
UITabBar.appearance().unselectedItemTintColor = UIColor.white.withAlphaComponent(0.6)
UITabBar.appearance().autoresizesSubviews = true
UITabBar.appearance().backgroundColor = UIColor(named: "CustomOrange")
}
var body: some View {
ZStack {
TabView(selection: $selectedTab) {
Settings(auth: auth)
.tabItem {
Image(systemName: "gear")
Text("Settings")
}.tag(0)
当我将选项卡 View 栏的颜色设置为自定义橙色时:
UITabBar.appearance().barTintColor = UIColor(named: "CustomOrange")
它始终默认为系统橙色(相当于Color.orange
)
我的定制橙色是#ff8000。
标签栏颜色是否仅限于系统颜色?
最佳答案
与 Xcode 12/iOS 14 配合良好。它是一种淡色(非纯色)(如果您使用选择器来测试结果)。要获得纯分配的颜色,您必须禁用半透明
UITabBar.appearance().isTranslucent = false
关于ios - SwiftUI 的 TabView 颜色无法更改为自定义颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63749519/