Reputation: 5420
I am trying to add a pdf image to tabbar item in swiftUI and I am facing problem that it is not resizing to small tabbar item here is my code.
struct RootTabView: View {
init() {
UITabBar.appearance().barTintColor = UIColor.appBlue
}
var body: some View {
TabView{
HomeView()
.tabItem({
Image("Home") // This is a pdf image all other are normal png images
.fixedSize()
.frame(width: 20, height: 20, alignment: .center)
.aspectRatio(contentMode: .fit)
.imageScale(.small)
.scaledToFit()
Text("Home")
})
AccountView()
.tabItem({
Image("img_panel_home") // PNG image
Text("Account")
})
SettingsView()
.tabItem({
Image("img_panel_home")
Text("Settings")
})
HelpView()
.tabItem({
Image("img_panel_home")
Text("Help")
})
}
.accentColor(Color(red: 135/255, green: 245/255, blue: 255/255))
}
}
and the Output is
PDF image that I used Home.pdf
Xcode version 11.6
Upvotes: 0
Views: 902
Reputation: 478
try this:
HomeView()
.tabItem({
Image("Home")
.resizable() // add this line
.fixedSize()
.frame(width: 20, height: 20, alignment: .center)
.aspectRatio(contentMode: .fit)
.imageScale(.small)
.scaledToFit()
Text("Home")
})
Upvotes: 2