Custom UINavigationBar subclass with gradient colors on iOS.
- iOS SDK 7.0 or later
- CocoaPods
Add the following line to your Podfile:
pod "JXGradientNavigationBar"
- Import the header file:
#import "JXGradientNavigationBar.h"
- Set the gradient colors using UIAppearance
barTintGradientColors
property:
[JXGradientNavigationBar appearance].barTintGradientColors = @[[UIColor greenColor], [UIColor yellowColor]];
- Customize your navigation controller:
UINavigationController * navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[JXGradientNavigationBar class] toolbarClass:nil];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[JXGradientNavigationBar appearance].barTintGradientColors = @[[UIColor greenColor], [UIColor yellowColor]];
[JXGradientNavigationBar appearance].shadowImage = [[UIImage alloc] init];
[JXGradientNavigationBar appearance].tintColor = [UIColor whiteColor];
[JXGradientNavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
UINavigationController * navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[JXGradientNavigationBar class] toolbarClass:nil];
navigationController.navigationBar.translucent = YES;
navigationController.viewControllers = @[[[UIViewController alloc] init]];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
return YES;
}
Copyright © 2015 Jianqiu Xiao [email protected] under The MIT License.