【问题标题】:iOS 7 UITabBar badge positioniOS 7 UITabBar 徽章位置
【发布时间】:2013-10-03 17:40:31
【问题描述】:

有什么方法可以调整 iOS 7 中 UITabBar 徽章的位置吗?徽章现在比我想要的更能阻挡标签栏图标。

iOS 6:

iOS 7:

【问题讨论】:

    标签: ios objective-c uitabbarcontroller ios7 uitabbar


    【解决方案1】:

    看起来徽章被放置在相对于图像的特定位置。所以如果你没有图片,徽章在tabBarItem的左上角。

    所以 - 要定位徽章,请调整您用于 tabBarItem 图像的 .png 周围空白像素的边框。

    【讨论】:

      【解决方案2】:

      如果可能,能否提供设置标签栏图像的方法?

      我遇到了和你一样的问题,并使用UIImageRenderingModeAlwaysOriginal修复了它:

      UIImage *image = // Your tab bar item image
      UIImage *selected = // Your selected tab bar item image
      
      image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
      selected = [selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
      
      controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:title
                                                            image:image
                                                    selectedImage:selected];
      

      干杯!

      【讨论】:

      • 这仅修复了未选择的图像。为我选择的图像看起来仍然像正在应用阴影。有什么帮助吗?
      • @Halsafar,您还需要设置选项卡项选择的图像。如果您没有设置选中的图片和未选中的图片,iOS 7 的徽章会覆盖您的图片。添加 [tabBarItem setSelectedImage: selectedImage];到您的 tabBar 控制器 viewDidLoad 方法应该可以解决您的问题。
      【解决方案3】:

      无法调整徽章的外观。

      如果你真的想让它与众不同,我认为在UITabBar 上实现自定义覆盖应该很容易。这样您就可以在其中放置任何自定义文本,而不仅仅是数字。

      【讨论】:

        【解决方案4】:

        iOS 7 SDK 弃用我们自定义tabbar的3个关键方法

        - (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage
        
        - (UIImage *)finishedUnselectedImage
        
        - (UIImage *)finishedSelectedImage
        

        正如@Daniel Amitay 所建议的那样,他们在文档中提出了替代方案。

        文档在这里

        https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarItem_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UITabBarItem/setFinishedSelectedImage:withFinishedUnselectedImage:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-06-22
          • 1970-01-01
          • 2014-02-23
          • 2015-06-03
          • 1970-01-01
          • 1970-01-01
          • 2017-08-09
          • 1970-01-01
          相关资源
          最近更新 更多