ios - 快速更改导航 Controller 颜色

标签 ios swift uinavigationbar

我想将导航栏色调 Controller 颜色更改为颜色:R:73,G:155,B:255,A:0.7

到目前为止,我只能将其更改为系统中的颜色。这是委托(delegate)中的示例:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {

    UINavigationBar.appearance().barTintColor = UIColor.blueColor()
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()

    return true
}

另外,我也希望能够将导航 View Controller 的标题颜色也更改为白色!

如果可能的话,我想将标签栏的色调颜色更改为 R: 73、G: 155、B: 255、A: 0.7,并将它们的文本更改为白色。

最佳答案

如果要设置导航栏的背景颜色:

UINavigationBar.appearance().barTintColor = UIColor.redColor()

请注意 RGB 值介于 0.0 到 1.0 之间,因此您必须将它们除以 255,否则您的颜色将只是白色。下一个色调:

UINavigationBar.appearance().tintColor = UIColor(red: 73.0 / 255.0, green: 155.0 / 255.0, blue: 255.0/ 255.0, alpha: 1.0)

然后设置标题文本:

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: someColor, NSFontAttributeName: someFont]

最后是条形按钮项目:

UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: color, NSFontAttributeName: buttonFont], forState: UIControlState.Normal)

关于ios - 快速更改导航 Controller 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27451977/

相关文章:

json - Int 不符合协议(protocol) 'StringLiteralConvertible'

ios - UINavigationBar 中的雪佛龙在显示弹出窗口时不会变暗

iphone - 如何更改...更多导航的标题

iOS 共享表/扩展不褪色状态栏

objective-c - 使用来自 NSURL 的 UIImage 存储图像

动画与 swift

ios - 空白代替隐藏的标签栏

iphone - CGContextRotateCTM 没有旋转 UIButton

ios - 在 Collection View 的容器 View 中呈现 View Controller didSelectItemAtIndexPath swift

ios - 解开可选值错误 - 检查应用内购买的收据响应