首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像在UITabBarItem中的位置

图像在UITabBarItem中的位置
EN

Stack Overflow用户
提问于 2012-09-15 20:38:14
回答 1查看 4.2K关注 0票数 0

我正在使用代码来显示一个项目的UITabBar,我下载了一个例子,显示项目与系统图标的“收藏”“联系人”…

代码语言:javascript
复制
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];

我想使用我自己的图像,所以我更改了第一行(收藏夹),但当我设置它时,图像是从中间开始的,并且总是留在标题的小位置,即使它是空的。

如何控制这些项目中的图像位置?并禁用空的头衔位置?

EN

回答 1

Stack Overflow用户

发布于 2015-09-16 16:30:54

这是一个相当古老的问题,但即使是古老的问题也需要关爱:)

因此,如果您仍然有这个问题,可以使用UIViewController的选项卡栏项目image insets:tabBarItem.imageInsets

您可以在视图控制器上设置此属性,并将其分配给选项卡栏控制器的viewControllers属性。

这是一个子类化标签栏控制器的快速版本,它将始终确保所有图像都对齐得更低一点。

代码语言:javascript
复制
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)
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12437452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档