我正在使用代码来显示一个项目的UITabBar,我下载了一个例子,显示项目与系统图标的“收藏”“联系人”…
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];我想使用我自己的图像,所以我更改了第一行(收藏夹),但当我设置它时,图像是从中间开始的,并且总是留在标题的小位置,即使它是空的。
如何控制这些项目中的图像位置?并禁用空的头衔位置?
发布于 2015-09-16 16:30:54
这是一个相当古老的问题,但即使是古老的问题也需要关爱:)
因此,如果您仍然有这个问题,可以使用UIViewController的选项卡栏项目image insets:tabBarItem.imageInsets。
您可以在视图控制器上设置此属性,并将其分配给选项卡栏控制器的viewControllers属性。
这是一个子类化标签栏控制器的快速版本,它将始终确保所有图像都对齐得更低一点。
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)
}
}https://stackoverflow.com/questions/12437452
复制相似问题