【问题标题】:ios tabbar put text in the middle when no imageios标签栏在没有图像时将文本放在中间
【发布时间】:2012-09-17 04:11:44
【问题描述】:

我的标签栏只包含文本,没有图像。
问题是文本总是显示在标签的底部,有没有办法将文本定位在中间?

谢谢

【问题讨论】:

    标签: objective-c ios5 uitabbar uitabbaritem


    【解决方案1】:

    知道了!

    [tab.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -10)]

    【讨论】:

    • 我正在尝试同样的事情,但它不起作用。我们还需要做其他事情吗?
    • 不,就是这样。你把它放在哪里?
    • 为什么是 (0, -10)?我不明白...你能解释一下吗?
    • 基于文档developer.apple.com/library/ios/documentation/UIKit/Reference/… UIOffset are positive for right or down, negative for left or up.,默认情况下iOS认为有图像所以将文本放在底部,我们想要的是提升文本。值 10 是通过反复试验:)
    【解决方案2】:

    补充一下,如果你在tabBarController中设置了multi viewControllers,你应该使用如下:

    for (UITabBarItem* item in tabBarController.tabBar.items)
    {
        [item setTitlePositionAdjustment:UIOffsetMake(0, -10)];
    }
    

    【讨论】:

      【解决方案3】:

      快速更新。

      func tabBarItem(title: String, imageName: String, selectedImageName: String, tagIndex: Int) -> UITabBarItem {
              let item = UITabBarItem(title: title,
                                      image: UIImage(named: imageName),
                                      selectedImage: UIImage(named: selectedImageName))
              item.titlePositionAdjustment = UIOffset(horizontal:0, vertical:-10)
              item.tag = tagIndex
              return item
          }
      

      //例如

      let window = UIWindow.window()
      let vc = UIViewController()
      vc.tabBarItem = tabBarItem(title: "More", imageName: "icon_more", selectedImageName: "icon_more", tagIndex: 1)
      
      
      let mainTBC = UITabBarController()
          mainTBC.viewControllers = [vc]
       window?.rootViewController = mainTBC
       window?.makeKeyAndVisible()
      

      【讨论】:

        猜你喜欢
        • 2011-12-24
        • 2015-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-14
        • 2015-09-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多