我想在导航栏的左上角添加徽标。我试着在设计时间,但没有为我工作。
下面是我想要的截图。
以下是我尝试的代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let imgLogo : UIImage = UIImage(named:"Logo")!
let imgViewLogo : UIImageView = UIImageView(image: imgLogo)
imgViewLogo.frame = CGRectMake(20, 2, 60, 60)
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let objNavigationController = UINavigationController()
objNavigationController.navigationBar.addSubview(imgViewLogo)
let mainView = ViewController(nibName: nil, bundle: nil)
objNavigationController.viewControllers = [mainView]
self.window!.rootViewController = objNavigationController
self.window?.makeKeyAndVisible()
return true
}
任何帮助都将不胜感激。
答案 0 :(得分:3)
你必须将它放在UIImageView
中let logo = UIImage(named: "logo.png")
let imageView = UIImageView(image:logo)
self.navigationItem.titleView = imageView