如何更改UINavigationItem的背景颜色? [英] How to change background color of UINavigationItem?

查看:400
本文介绍了如何更改UINavigationItem的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 UINavigationItem ,但我在属性检查器中找不到tittle,prompt和back按钮旁边的任何内容

I have a UINavigationItem, but I can't found anything beside tittle, prompt, and back button in attribute inspector

I想知道如何使用代码更改 UINavigationItem 背景颜色?或以编程方式?

I wonder how can I change my UINavigationItem background color using code? or programmatically?

推荐答案

您可以通过代码更改它......

You can change it through code...

对于Objective-C:

    self.navigationController.navigationBar.barTintColor = [UIColor redColor];

在viewDidLoad方法中写入以上行。

Write Above line in viewDidLoad method.

对于Swift:

    self.navigationController?.navigationBar.barStyle = UIBarStyle.BlackTranslucent

    self.navigationController?.navigationBar.barTintColor  = UIColor.redColor();

OR

    self.navigationController!.navigationBar .setBackgroundImage(UIImage .new(), forBarMetrics: UIBarMetrics.Default)
    self.navigationController!.navigationBar.shadowImage = UIImage .new();
    self.navigationController!.navigationBar.translucent = true;
    self.navigationController!.navigationBar.backgroundColor = UIColor.redColor();

您可以根据自己的选择更改颜色。

You can change color on your own choice.

更改栏文字...

navigationController.navigationBar.titleTextAttributes = [UITextAttributeTextColor: UIColor.blueColor()]

参见链接....
这里

见上图...你像这样的屏幕右侧输出...... !!!

See the above image... you like output like this screen right...!!!

这篇关于如何更改UINavigationItem的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆