Friday 24 February 2017

Mix navigation bar with main view

In iOS when it comes to work with navigation controller, we need to handle different aspects of the UINavigation bar which is a property of the UINavigationController. 
In my last app , I need to merge the navigation bar into main view to mimic the user there is no navigation bar but still have bar buttons and title in it.

Here I am showing some small but important work we can do with UINavigation bar, which I come up with :

1) Add animation to title of the navigation bar 

 let lblTitle = UILabel(frame:CGRect(x:0, y:0,width:50, height: 50))  
        lblTitle.text = "Items"
        lblTitle.textColor = UIColor.white
         self.navigationItem.titleView = lblTitle
        
        let animation  = CATransition()
        animation.duration  = 3.0
        animation.type = kCATransitionPush

        lblTitle.layer.add(animation, forKey:"moveText")

2) Mix the navigation bar into main view of the screen


 To merge the navigation bar into our main view, we have to remove the separator line between navigation bar and main view. And then cha

To remove the separator line , set background image and shadow image to a blank UIImage , like this one: 

Now change the background color of the navigator bar with the color of main view
        
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()

If the default background image is used then default shadowImage also used. So to make it work backgroundImage must be changed with shadowImage.




No comments:

Post a Comment