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

NavigationBar bar, tint, and title text color in iOS 8

In AppDelegate.swift, in application(_:didFinishLaunchingWithOptions:) I put the following: UINavigationBar.appearance().barTintColor = UIColor(red: 234.0/255.0, green: 46.0/255.0, blue: 73.0/255.0, alpha: 1.0) UINavigationBar.appearance().tintColor = UIColor.white UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white] (For Swift 4 or earlier use NSAttributedStringKey instead of NSAttributedString.Key) For titleTextAttributes, the docs say: You can specify the font, text color, text shadow color, and text shadow offset … Read more

iOS 7 | Navigation bar / Toolbar buttons very close to status bar

The navigation bars or toolbars have to be at (0, viewController.topLayoutGuide.length) with bar positioning of UIBarPositionTopAttached. You should set the delegate of your navigation bar or your toolbar to your view controller, and return UIBarPositionTopAttached. If positioned correctly, you will have the result in your third image. More information here: https://developer.apple.com/documentation/uikit/uibarpositioningdelegate?language=objc

How to make completely transparent navigation bar in iOS 7

From this answer [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [UIImage new]; self.navigationController.navigationBar.translucent = YES; self.navigationController.view.backgroundColor = [UIColor clearColor]; self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]; Also, as suggested by Josh in the comments, to put the bar back to default: [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

Add a UIView above all, even the navigation bar

You can do that by adding your view directly to the keyWindow: UIView *myView = /* <- Your custom view */; UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow; [currentWindow addSubview:myView]; UPDATE — For Swift 4.1 and above let currentWindow: UIWindow? = UIApplication.shared.keyWindow currentWindow?.addSubview(myView) UPDATE for iOS13 and above keyWindow is deprecated. You should use the following: UIApplication.shared.windows.first(where: … Read more