【问题标题】:Tab Bar - custom images without titles标签栏 - 没有标题的自定义图像
【发布时间】:2015-03-07 02:53:52
【问题描述】:

我想将我的标签栏设置为具有自定义图像,但 XCode 坚持为标签栏项目标题文本留出空间,使我的图像在标签栏中的位置太高。我在 TabBarController.swift viewDidLoad 函数中尝试了以下代码:

let tabItems = tabBar.items as [UITabBarItem]
     tabItems[0].title = nil
    tabItems[0].selectedImage = UIImage(named: "HomeWhiteIcon")
    tabItems[1].title = "Database"
    tabItems[1].selectedImage = UIImage(named: "Second")
    tabItems[2].title = nil
    tabItems[2].selectedImage = UIImage(named: "SettingsWhiteIcon")
    tabItems[3].title = nil
    tabItems[3].selectedImage = UIImage(named: "ReportsWhiteIcon")

然而,虽然没有显示标题,但图像位置太高,如下图所示(请忽略数据库图标 - 我尚未设置此图标。

【问题讨论】:

    标签: swift icons tabbar


    【解决方案1】:

    这是一个随机的 stab,因为 swift 不是我的强项,但也许具有标题的数据库图标会导致整个标题行不折叠。尝试从数据库图标中删除标题。

    否则你见过setTitlePositionAdjustment 方法吗?也许将标题的位置向上调整到图标中,下面的空间就会消失。

    【讨论】:

    • 有趣 - 当我从情节提要中删除数据库标题并执行项目清理时,数据库标题仍然显示。
    • 我的错误 - 我仍然在我的 tabBarViewController 中进行了编程。是的,如果我还应用图像插图,您的建议似乎有效。这似乎是一个粗略的解决方法。我想知道我们是否遗漏了什么?
    • 实际上,调整插图似乎是一种公认​​的方式:stackoverflow.com/a/16568865/1828107
    猜你喜欢
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2014-11-17
    相关资源
    最近更新 更多