【问题标题】:Change color of tab bar更改标签栏的颜色
【发布时间】:2012-08-25 16:02:23
【问题描述】:

我在 iOS 5 中使用 Storyboard 创建了一个应用程序来布置我的屏幕。我有一个标签栏控制器和带有 4 个图标的底部标签栏。我想将颜色从黑色更改为渐变绿色。我可以制作一个 .png 文件,但不知道如何用我的绿色填充替换黑色填充。

我看过一些关于代码的帖子,但似乎 iOS 5 与运行 iOS4 的设备不同,我不知道将代码放在哪里。

谢谢

【问题讨论】:

    标签: ios tabs controller appearance


    【解决方案1】:

    这对我有用:

    在 AppDelegate.m 中,我将以下代码放在 // 应用程序启动后自定义覆盖点之后。

    [[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
    

    希望这会有所帮助:)

    【讨论】:

      【解决方案2】:

      您可以通过选择根来设置情节提要上的颜色:Tab Bar View Controller,选择标签栏,然后在属性检查器中调整背景(或色调)颜色,或者您可以使用 barTintColor 调整代码:

      // Adjust the Color of the Tab Bar itself
      self.tabBar.barTintColor = [UIColor redColor];
      
      // Adjust the Color of the selected Icon in the Tab Bar
      self.tabBar.tintColor = [Single single].singleThemeColorTint;

      如果你也需要调整 ALPHA,我会使用:

      UIColor *charcoal = [UIColor colorWithRed:66/255.0
                                                  green:79/255.0
                                                   blue:91/255.0
                                                  alpha:1];
        	// For Tab Bar
          self.tabBar.barTintColor = charcoal;
      
      	// For selected Item Highlight
          self.tabBar.tintColor = charcoal;

      我为 Tab Bar Story Board 创建了一个视图控制器文件,并在 ViewDidLoad{ }

      中运行了此代码

      【讨论】:

        【解决方案3】:

        这是 Ray WenderLich 的精彩博文。

        iOS5 中的用户界面自定义

        http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5

        【讨论】:

        • 谢谢,我复习了那个教程,看看我能不能弄清楚颜色的变化。
        【解决方案4】:

        如果您使用故事板 API 创建应用程序,那么您将无法支持 iOS4,它们依赖于新的运行时类,而这些类在其中不可用。

        【讨论】:

        • 谢谢,我不知道。在您看来,发布一个不能在 iOS 4 上运行的应用程序是否有很大的负面影响?
        • 不,因为大多数设备都有 iOS5 更新并且 iOS6 版本即将发布...Apple 将尝试弃用 iOS5 之前的 SDK 中的许多框架支持
        猜你喜欢
        • 2014-12-23
        • 1970-01-01
        • 2013-06-11
        • 2016-08-20
        • 1970-01-01
        • 1970-01-01
        • 2013-11-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多