I'm using code to shown a UITabBar with items, I downloaded an example that show item with system icons of "favorites" "contacts" ...
UITabBarItem *favorites = [[UITabBarItem alloc] initWithTitle:nil image:a1 tag:0];
UITabBarItem *topRated = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:1];
UITabBarItem *featured = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:2];
UITabBarItem *recents = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:3];
I want to use my own images so i changed the first line (favorites), but when i setting it, the image is starting in the middle, and always stays a small place for title,even if it's empty.
How can I controll the image possition inside those items? and disable the empty title place?
It's a fairly old question but even old questions need love :)
So if you're still having this problem you can use the UIViewController
s tab bar item image insets: tabBarItem.imageInsets
.
You set this on view controllers which you will assign to viewControllers
property of the tab bar controller.
Here is a swift version of a subclassed tab bar controller which will always ensure all images are aligned a bit lower.
override func setViewControllers(viewControllers: [AnyObject], animated: Bool) {
super.setViewControllers(viewControllers, animated: animated)
let array = viewControllers as! [UIViewController]
for controller in array {
controller.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.