【问题标题】:Changing the background color of only one UITabBarItem仅更改一个 UITabBarItem 的背景颜色
【发布时间】:2016-08-19 22:20:07
【问题描述】:

我正在尝试创建一个类似于 Instragram 旧标签栏的外观,其中中间的标签按钮是“上传”按钮 (old tabbar pictured on top)。单击此按钮后,标签栏将被隐藏,您将进入上传屏幕,然后您可以通过左上角的按钮取消。如何仅围绕一个标签栏项目创建不同颜色的背景?

它甚至会是一个标签栏项目,还是一个放置在标签栏中间位置的按钮,将您带到模态转场?

【问题讨论】:

    标签: swift swift2 uitabbar uitabbaritem


    【解决方案1】:

    您可以通过UITabBarController.tabBar.subviews[index] 访问每个标签栏项的 UIView。在这种情况下,索引是基于 1 的 - 例如第一个选项卡是 1。显然,当您获取 UIView 时,您可以设置背景颜色。

    【讨论】:

    • 我将如何访问TabBarUITabBar 没有 .subviews[],当我尝试从情节提要连接到 TabBarController.swift 时,我得到 Getter for 'tabBar' with Objective-C selector 'tabBar' conflicts with getter for 'tabBar' from superclass 'UITabBarController' with the same Objective-C selectorProperty 'tabBar' with type 'UITabBar!' cannot override a property with type 'UITabBar'
    • @TommyK 从 TabBar 的 ViewController 你应该能够访问 TabBar(我使用 Xamarin,所以我不确定它在 XCode 中是如何大写的,可能它只是 tabBar)。
    • @TommyK,你可以从UITabBarController访问tabBar,我会更新答案更清楚developer.apple.com/library/ios/documentation/UIKit/Reference/…
    • @TommyK 和 UITabBar 继承自 UIView(或者用 Swift 术语来说是 UIView 的子类),因此它具有子视图,就像 UIView 一样。
    • 仍然不适合我。当我选择UITabBarController时,它后面的唯一选项是所有方法tabBar(self: UITabBarController),而不仅仅是.tabBar.subviews。如果我尝试输入你写的内容,我会得到Ambiguous reference to member 'tabBar(_:didSelectItem:)'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    相关资源
    最近更新 更多