我正在尝试为整个应用自定义导航栏,但它无法在iOS模拟器中运行。 我使用MasterDetail模板创建了一个项目。
在AppDelegate.swift中
import UIKit
import CoreData
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch
let navigationController = self.window!.rootViewController as UINavigationController
let controller = navigationController.topViewController as MasterViewController
controller.managedObjectContext = self.managedObjectContext
var navigationBarAppearance = UINavigationBar.appearance()
navigationBarAppearance.tintColor = UIColor.darkGrayColor()
navigationBarAppearance.barTintColor = UIColor.whiteColor()
if let font = UIFont(name: "Bariol Regular", size: 20) {
navigationBarAppearance.titleTextAttributes = [
NSFontAttributeName: font,
NSForegroundColorAttributeName: UIColor.whiteColor()]
}
return true
}
}