8

i have developed an iPad app. In that app i have 4 separate views embedded inside a single view controller and there is a navigation bar for each view.I want to set the corner radius of each navigation bar.

i tried

       customNavigationBar.layer.cornerRadius = 25;

but this piece of code is not working. Does anyone know how to set the corner radius for each navigation bar.

Sandy
  • 343
  • 3
  • 7
  • 18

4 Answers4

21
customNavigationBar.layer.cornerRadius=25;
customNavigationBar.clipsToBounds=YES;

i have tested it successfully

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
hayden
  • 293
  • 1
  • 5
  • 2
    This solution doesn't work well if you have background colour set and wish to keep status bar in the same colour. clipsToBounds prevents UINavigationBar from covering status bar, it ends on safe area. – Andrzej Polis Jan 05 '21 at 17:48
13

Swift 4: Also if you only want the top edges of the navigation bar to have rounded corners, you can try this

override func viewDidAppear(_ animated: Bool) {
    self.navigationController?.navigationBar.layer.cornerRadius = 20
    self.navigationController?.navigationBar.clipsToBounds = true
    self.navigationController?.navigationBar.layer.maskedCorners = [.layerMinXMinYCorner,.layerMaxXMinYCorner]
}
Naishta
  • 11,885
  • 4
  • 72
  • 54
2

Add an image with corner rounded as background of navigation bar to make it happen. Check this link Applying rounded corners for the whole application

Community
  • 1
  • 1
Neo
  • 936
  • 6
  • 17
1

add quartcore framework and than

in .h file of header

#import <QuartzCore/QuartzCore.h>

and write code as below

self.navigationController.navigationBar.layer.cornerRadius=25;
iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
hayden
  • 293
  • 1
  • 5