加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 如何改变导航栏的颜色?

发布时间:2020-12-14 04:50:14 所属栏目:百科 来源:网络整理
导读:我放了一个导航栏,但我不知道如何更改它的颜色,我试图在Main.storyboard中做它但它不起作用,然后我试着用代码做但我不知道怎么做究竟. 有人可以帮我怎么做吗? 解决方法 这是其中一种方式. 进入AppDelegate类并在func应用程序中编写这些代码(应用程序:UIApp
我放了一个导航栏,但我不知道如何更改它的颜色,我试图在Main.storyboard中做它但它不起作用,然后我试着用代码做但我不知道怎么做究竟.
有人可以帮我怎么做吗?

解决方法

这是其中一种方式.
进入AppDelegate类并在func应用程序中编写这些代码(应用程序:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) – >布尔

Swift 3.0更新

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder,UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    UINavigationBar.appearance().barTintColor = UIColor.white   //1
    UINavigationBar.appearance().tintColor = UIColor.red   //2
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.red]   //3

    return true
}

这个是导航栏的背景颜色

UINavigationBar.appearance().barTintColor = UIColor.white   //1

对于导航栏中项目的颜色

UINavigationBar.appearance().tintColor = UIColor.red   //2

对于导航栏中的tittle颜色.

UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.red]   //3

如果你想要你可以用你想要的颜色(自定义颜色)来改变它,使用它(而不是.white,.red或任何其他颜色)

UIColor(red: 49/255,green: 75/255,blue: 108/255,alpha: 1.0) //Custom Color

这只是一个如何使用它的例子,我想你知道如何使用颜色,alpha是透明度,所以alpha:1.0是100%透明度.

如果您有任何问题,请在评论中提问.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读