Sandy
Sandy

Reputation: 353

Corner radius for a navigation bar

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.

Upvotes: 8

Views: 11185

Answers (4)

Naishta
Naishta

Reputation: 12383

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]
}

Upvotes: 13

hayden
hayden

Reputation: 293

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;

Upvotes: 1

hayden
hayden

Reputation: 293

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

i have tested it successfully

Upvotes: 21

Neo
Neo

Reputation: 936

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

Upvotes: 2

Related Questions