How to remove border of the navigationBar in swift?

The trouble is with these two lines: self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: “”), forBarMetrics: UIBarMetrics.Default) self.navigationController?.navigationBar.shadowImage = UIImage(named: “”) Since you don’t have an image with no name, UIImage(named: “”) returns nil, which means the default behavior kicks in: When non-nil, a custom shadow image to show instead of the default shadow image. For a custom shadow to be … Read more

Programmatically get height of navigation bar

Do something like this ? NSLog(@”Navframe Height=%f”, self.navigationController.navigationBar.frame.size.height); The swift version is located here UPDATE iOS 13 As the statusBarFrame was deprecated in iOS13 you can use this: extension UIViewController { /** * Height of status bar + navigation bar (if navigation bar exist) */ var topbarHeight: CGFloat { return (view.window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0) + (self.navigationController?.navigationBar.frame.height … Read more

Navigation bar show/hide

This isn’t something that can fit into a few lines of code, but this is one approach that might work for you. To hide the navigation bar: [[self navigationController] setNavigationBarHidden:YES animated:YES]; To show it: [[self navigationController] setNavigationBarHidden:NO animated:YES]; Documentation for this method is available here. To listen for a “double click” or double-tap, subclass UIView … Read more

How to resize Title in a navigation bar dynamically

Used the below code in ViewDidload . Objective C self.title = @”Your TiTle Text”; UILabel* tlabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 40)]; tlabel.text=self.navigationItem.title; tlabel.textColor=[UIColor whiteColor]; tlabel.font = [UIFont fontWithName:@”Helvetica-Bold” size: 30.0]; tlabel.backgroundColor =[UIColor clearColor]; tlabel.adjustsFontSizeToFitWidth=YES; tlabel.textAlignment = NSTextAlignmentCenter; self.navigationItem.titleView=tlabel; Swift Version self.title = “Your Title Text” let tlabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: … Read more

How to hide the navigation bar and toolbar as scroll down? Swift (like myBridge app)

Try this simple approach: Tested in Swift 3 func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { if(velocity.y>0) { //Code will work without the animation block.I am using animation block incase if you want to set any delay to it. UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { self.navigationController?.setNavigationBarHidden(true, animated: true) self.navigationController?.setToolbarHidden(true, animated: true) … Read more

How can I set the UINavigationbar with gradient color?

Details Xcode 11.4 (11E146), swift 5 Tested on iOS 13.1, 12.2, 11.0.1 Solution class UINavigationBarGradientView: UIView { enum Point { case topRight, topLeft case bottomRight, bottomLeft case custom(point: CGPoint) var point: CGPoint { switch self { case .topRight: return CGPoint(x: 1, y: 0) case .topLeft: return CGPoint(x: 0, y: 0) case .bottomRight: return CGPoint(x: 1, … Read more

UINavigationBar multi-line title

Set the titleView property of the UINavigationItem. For example, in the view controller’s viewDidLoad method you could do something like: UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)]; label.backgroundColor = [UIColor clearColor]; label.numberOfLines = 2; label.font = [UIFont boldSystemFontOfSize: 14.0f]; label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; label.textAlignment = UITextAlignmentCenter; label.textColor = [UIColor whiteColor]; label.text = … Read more

UIBarButtonItem with custom view not properly aligned on iOS 7 when used as left or right navigation bar items

Works until iOS11! You can use negative flexible spaces and rightBarButtonItems property instead of rightBarButtonItem: UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; spacer.width = -10; // for example shift right bar button to the right self.navigationItem.rightBarButtonItems = @[spacer, yourBarButton];