前言:
最近看了下SwiftUI一些基礎語法,自己寫了基本的語法,在寫SwiftUI時,不要把OC的思想拿過來用,完全不同的概念的,swiftUI多協議,此view非彼view😂😂,寫過swiftUI代碼的童鞋一定會深有感觸,在此我這有一個swiftUI思想概念的講解,也在下面這個地址中,如果想了解,可以下載看下。
另外swiftUI的基本語法我已經都寫了一遍,按照蘋果官網來寫的,地址在此,還在持續更新中,如果感興趣,童鞋們可以看看撒~~~~
下面直接上代碼,如何改變TabView底部顏色以及tabItem顏色
----- show time -----
//更改TabItem(文本+圖標)顏色
init() {
UITabBar.appearance().unselectedItemTintColor = UIColor.white
}
更改TabView背景顏色
init() {
UITabBar.appearance().backgroundColor = UIColor.red
UITabBar.appearance().backgroundImage = UIImage()
}
上面的方法親測有效
整個Demo代碼如下:
struct TableViewTest: View {
@State private var ff: String = ""
init() {
UITabBar.appearance().backgroundColor = UIColor.purple
UITabBar.appearance().backgroundImage = UIImage()
}
var body: some View {
TabView {
Text("The First Tab")
.tabItem {
Image(systemName: "1.square.fill")
Text("First")
}
.background(Color.green)
Text("Another Tab")
.tabItem {
Image(systemName: "2.square.fill")
//.resizable()
//.frame(width: 20, height: 20, alignment: .center)
Text("Second")
}
Text("The Last Tab")
.tabItem {
Image(systemName: "3.square.fill")
Text("Third")
}
.background(Color.red)
}.accentColor(.green)
.font(.headline)
}
}
後續會更新一些swiftUI的問題或者使用過程中遇到的一些有趣的問題,如果童鞋們有問題,可以留言交流哦~