'Function holds System Image rather than image
@ViewBuilder
func TabButton (image: String)-> some View{
Button {
withAnimation{currentTab = image}
} label: {
Image(image)
.resizable()
.renderingMode(.original)
.aspectRatio(contentMode: .fit)
.frame(width: 23, height: 22)
.foregroundColor(currentTab == image ? .primary : .gray)
.frame(maxWidth: .infinity)
}.buttonStyle(GradientButtonStyle())
}
}
I want rather than image from assets as input, system image whom is variable is input here and can change each time and not fixed. thank you
I use it like this,
struct MainView: View {
@State var showMenu: Bool = false
// Hiding Native One.
init(){
UITabBar.appearance().isHidden = true
}
@State var currentTab = "Home"
//offset for both drag gesture and showing menu.
@State var offset: CGFloat = 0
@State var lastStoredOffset: CGFloat = 0
var body: some View {
//let sideBarWidth = getRect().width - 90
// whole navigation view....
NavigationView{
HStack(spacing : 0){
//Side Menu
//SideMenu(showMenu: $showMenu)
//Main Tab View
VStack(spacing: 0){
TabView(selection: $currentTab){
Home(showMenu: $showMenu)
.navigationBarTitleDisplayMode(.inline)
.navigationBarHidden(true)
.tag("Home")
}
this is the tabview code up
VStack(spacing: 0)
{ Divider()
HStack(spacing:0){
// tab buttons
TabButton(image: "Home")
}
}
}
}
I want system image rather than image here , need help please!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
