user8426652
user8426652

Reputation: 115

Adding an image to a tab bar item only shows up as a block

I have a tab bar which should have an image for the selected index.

Below is a sample-image which sould be used inside my tab bar.

tab bar image i want to add

I have added it by selecting the connected view controller assigned to the tab bar item and replacing the image. However this is what actually appears on the screen. The assigned graphics is not appearing on the tab bar.

The middle icon

Upvotes: 0

Views: 1772

Answers (3)

Nishant Bhindi
Nishant Bhindi

Reputation: 2252

set your tabBarImage in assets folder, And set Render as original Imageenter image description here

Upvotes: 3

Bilal
Bilal

Reputation: 19156

  1. Go to Assets.xcassets
  2. Select your image
  3. Show the Attributes Inspector
  4. Change Render As value form Default to Original Image

enter image description here

Upvotes: 4

Reinier Melian
Reinier Melian

Reputation: 20804

You can add this line self.tabBarItem.image = UIImage(named: "icono-menu")?.withRenderingMode(.alwaysOriginal) in your item viewController viewDidLoad

something like this

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.tabBarItem.image = UIImage(named: "icono-menu")?.withRenderingMode(.alwaysOriginal)
    }

Upvotes: 1

Related Questions