Jayprakash Dubey Jayprakash Dubey - 3 months ago 20x
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.


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()


let mainView = ViewController(nibName: nil, bundle: nil)
objNavigationController.viewControllers = [mainView]
self.window!.rootViewController = objNavigationController

return true

Any help would be appreciated.


You have to put it inside an UIImageView

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