Varun Naharia
Varun Naharia

Reputation: 5420

SwiftUI PDF image is not resizing

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

enter image description here

PDF image that I used Home.pdf

Xcode version 11.6

Upvotes: 0

Views: 902

Answers (1)

Hồng Phúc
Hồng Phúc

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

Related Questions