SMTNavigationBar simply centralizes your custom navigation bar. Create navigation buttons once and viola you can access it on any of your UIViewControllers.
pod 'SMTNavigationBar'
#import "UIViewController+SMTNavigationBar.h"
UIButton * leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
[leftBtn setTitle:@"left" forState:UIControlStateNormal];
[leftBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[self createButtonWithKey:@"leftBtn" button:leftBtn];
[self setLeftBarButtonItemWithKey:@"leftBtn" isDefault:YES isPop:YES];
-(void)viewWillAppear:(BOOL)animated{
[self loadDefaults];
}
/* List of items
LEFT_ITEM
RIGHT_ITEM
TITLE_ITEM
TITLEVIEW_ITEM
*/
[self loadDefaultWithItem:RIGHT_ITEM];
[self setLeftBarButtonItemWithKey:@"leftBtn" isDefault:YES withSelectorBlock:^(UIViewController *vc) {
//When controller is popped. VC becomes a uinavigationcontroller class.
if([vc isKindOfClass:[UINavigationController class]]){
UINavigationController * vcs = (UINavigationController *) vc;
vc = [vcs viewControllers].lastObject;
}
NSLog(@"This is the block method generated on first VC but is now being presented in %@",vc.navigationItem.title);
}];
Note: UIViewController * vc becomes a UINavigationController class if its presented after a pop. In such case use this inside the block
if([vc isKindOfClass:[UINavigationController class]]){
UINavigationController * vcs = (UINavigationController *) vc;
vc = [vcs viewControllers].lastObject;
}
[self runLeftSuperBlock];
[self runRightSuperBlock];
-(void)SMTNavigationBarDidTapLeftItem
-(void)SMTNavigationBarDidTapRightItem
-(void)SMTNavigationBarDidPop
UIImageView * imgView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
imgView.contentMode = UIViewContentModeScaleAspectFill;
imgView.clipsToBounds = NO;
[self createTitleViewWithKey:@"titleView" titleview:imgView];
[self setTitleViewWithKey:@"titleView" isDefault:YES];
[self setTitle:@"ABC" isDefault:YES];
1.2
v.1.2
- Added titleview customization
- Added support for navigation title
- Added loading of default items individually
- Included new titleview and title on reset and clear.
v.1.0
- Setting bar items
- Bar items block selectors
- Resetting values
- Clearing navigation bar
- Navigation bar configuration
- Swift counterpart
- Better documentation writeup
riza027 - https://github.com/riza027/
Fork, implement, pull request.
Copyright (c) 2015 Steffi Tan
See MIT-LICENSE for further details.