4 uinavigationcontroller swift
我放了一个导航栏,但我不知道如何更改它的颜色,我试图在Main.storyboard中做它但它不起作用,然后我试着用代码做但我不知道怎么做究竟.有人可以帮我怎么做吗?
这是其中一种方式.进入课堂AppDelegate并写下这些代码func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
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
}
Run Code Online (Sandbox Code Playgroud)
这个是导航栏的背景颜色
UINavigationBar.appearance().barTintColor = UIColor.white //1
Run Code Online (Sandbox Code Playgroud)
对于导航栏中项目的颜色
UINavigationBar.appearance().tintColor = UIColor.red //2
Run Code Online (Sandbox Code Playgroud)
对于导航栏中的tittle颜色.
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.red] //3
Run Code Online (Sandbox Code Playgroud)
如果你愿意,你可以改变它在什么都颜色,你想要的(自定义颜色),通过使用这种(而不是.white,.red或任何其他颜色)
UIColor(red: 49/255, green: 75/255, blue: 108/255, alpha: 1.0) //Custom Color
Run Code Online (Sandbox Code Playgroud)
这只是一个如何使用它的例子,我想你知道如何使用颜色,并且alpha是透明度,所以alpha: 1.0100%透明度.
如果您有任何问题,请在评论中提问.
使用代码:
navigationBar.barTintColor = UIColor.whiteColor()
Run Code Online (Sandbox Code Playgroud)
使用storyboard确保在Document Outline中选择Navigation Bar,然后在Utilities中显示Attributes Inspector(Xcode中的右侧窗口):
| 归档时间: |
|
| 查看次数: |
4852 次 |
| 最近记录: |