I am trying to implement an UITabBarController
with 2 UITabBarItems
. I added in storyboard the TabBarController. I have on important issue with
selectedImage
property of UITabBarItem
class.
The width of selectedImage
does not fit the tab. I changed between devices, and for every device the selected image is over the other tab, or does not fit the current tab. (I found a solution: to have the same image but with different width for every device. But for sure this is not a good solution)
The selected image is that one with orange line in the buttom.
Any idea ? Many thanks.
EDIT - Code updated
Here is the code which I implemented so far in class MMHomeVC: UITabBarController
:
if let arrTabBarItems = tabBar.items {
var tabBarItem1 = arrTabBarItems[0] as! UITabBarItem
var tabBarItem2 = arrTabBarItems[1] as! UITabBarItem
let imgHome = UIImage(named: "btnHome")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let imgProfile = UIImage(named: "btnProfile")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let imgSelectedTab = UIImage(named: "selectedTab_imgBackground")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let imgHomeTabSelected = UIImage(named: "tabHome_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let imgProfileTabSelected = UIImage(named: "tabProfile_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
tabBarItem1.image = imgHome
tabBarItem1.selectedImage = imgHomeTabSelected
tabBarItem2.image = imgProfile
tabBarItem2.selectedImage = imgProfileTabSelected
}
I played with AlwaysOriginal
and Automatic
but no success.