Reputation: 935
I have a UITabBar
with 3 items.
Each item has just an image (without a text).
What happens now is that all of the three images are presented in the center of each `tabBarItem.
What I want to accomplish is that the left UITabBarItem
's image will be aligned to the left. The middle UITabBarItem
's image will stay in the center, and the right UITabBarItem
will be aligned to the right.
I've searched all over the internet a way, but UITabBarItem
doesn't have any alignImage
property or something like that.
Any idea how can I do that?
Thank you!
Upvotes: 2
Views: 3648
Reputation: 2914
Can you try this? Basically you could set the insets of the image
property on your tabBarButton(UITabBarItem
). There could be another way but give a try.
let tabBarButton = UITabBarItem.init(title: "One", image: myImage, selectedImage: nil)
tabBarButton.image?.withAlignmentRectInsets(UIEdgeInsetsMake(0, 15, 0, 0))//Give your left alignment number
//one more way
tabBarButton.imageInsets = UIEdgeInsetsMake(0, 15, 0, 0)
Upvotes: 0
Reputation: 3157
You can do this by specifying horizontal value of "Custom offset" for UITabBarItem in Storyboard as per screenshot. (Note: give positive value for right TabBarItem to the right, negative value for left one and "Default position" for center one)
In device, it will look like as below:
Upvotes: 0