Jayprakash Dubey Jayprakash Dubey - 4 months ago 33
Swift Question

Add logo on navigation bar in top left corner using swift

I want to add logo on top left corner in Navigation Bar. I tried in design time but didn't worked for me.

Screenshot for design time

Below is grab of screenshot that I want.

Screenshot

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.

Answer

You have to put it inside an UIImageView

let logo = UIImage(named: "logo.png")
let imageView = UIImageView(image:logo)
self.navigationItem.titleView = imageView