Reputation: 36447
I want to add logo on top left corner in Navigation Bar. I tried in design time but didn't worked for me.
Below is grab of screenshot that I want.
Here is code that I tried :
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
}
Any help would be appreciated.
Upvotes: 2
Views: 1531
Reputation: 944
You have to put it inside an UIImageView
let logo = UIImage(named: "logo.png")
let imageView = UIImageView(image:logo)
self.navigationItem.titleView = imageView
Upvotes: 3