[[164113]] This basic framework mainly includes the extension of UITabBarController, UINavigationController and UIBarButtonItem classes. It mainly solves the problem of too many subviews being created, encapsulates the subview creation with UINavigationController, and then adds it to the ChildViewController view of UITabBarController. It also sets the font size and color of UITabBarItem of UITabBarController. Without further ado, here are the codes. 1. Inherit NPTabBarController created by UITabBarController 1. Set the font style on the tabbar - #pragma mark - Set the text above the tabbar setTitleTextAttributes
- - ( void )setTabBarTitleAttributesStyle
- {
- NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
-
- attrs[NSFontAttributeName] = [UIFont systemFontOfSize: 16 ];
-
- attrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
-
- NSMutableDictionary *selectAttrs = [NSMutableDictionary dictionary];
-
- selectAttrs[NSFontAttributeName] = [UIFont systemFontOfSize: 16 ];
-
- selectAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
-
-
- UITabBarItem *item = [UITabBarItem appearance];
-
- [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
-
- [item setTitleTextAttributes:selectAttrs forState:UIControlStateSelected];
- }
2. Navigation subview encapsulation - #pragma mark - Navigation subview encapsulation
- - ( void )setChildVC:(UIViewController *)ChildVC title:(NSString *)title image:(NSString *)image selectImgage:(NSString *)selectImage {
-
-
- NPNavigationController *nav = [[NPNavigationController alloc] initWithRootViewController:ChildVC];
-
- nav.tabBarItem.title = title;
-
- nav.tabBarItem.image = [UIImage imageNamed:image];
-
- nav.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];
-
- nav.view.backgroundColor = [UIColor grayColor];
-
- ChildVC.navigationItem.title = title;
-
- [self addChildViewController:nav];
-
- }
2. Inherit UINavigationController to create NPNavigationController 1. Rewrite -(void)pushVewController:(UIViewConntroller*)viewCOntroller animated:(Bool)animated method - - ( void )pushViewController:(UIViewController *)viewController animated:(BOOL)animated
-
-
- if (self.childViewControllers.count > 0 ) {
-
- UIButton *returnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
-
- [returnBtn setTitle:@ "return" forState:UIControlStateNormal];
-
- [returnBtn setImage:[UIImage imageNamed:@ "black" ] forState:UIControlStateNormal];
-
- [returnBtn setImage:[UIImage imageNamed:@ "grat" ] forState:UIControlStateHighlighted];
-
- [returnBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
-
- [returnBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
-
- [returnBtn setFrame:CGRectMake( 0 , 0 , 70 , 20 )];
-
- [returnBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
-
- [returnBtn setContentEdgeInsets:UIEdgeInsetsMake( 0 , 0 , 0 , 0 )];
-
- [returnBtn addTarget:self action: @selector (returnBtnClick) forControlEvents:UIControlEventTouchUpInside];
-
- viewController.hidesBottomBarWhenPushed = YES;
-
- viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:returnBtn];
- }
-
- [ super pushViewController:viewController animated:animated];
3. Add the UIBarButtonItem class extension UIBarButtonItem + NPBarbutton, create the UIbarbuttonItem class method 1. UIbarbuttonItem class method -
-
-
- + (instancetype)itemWithImage:(NSString *)image hightImage:(NSString *)hightImage target:(id)target action:(SEL)action
- {
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
- [btn setBackgroundImage:[UIImage imageNamed:hightImage] forState:UIControlStateNormal];
-
- CGSize btnsize = btn.currentBackgroundImage.size;
-
- [btn setFrame:CGRectMake( 0 , 0 , btnsize.width, btnsize.height)];
- [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
- return [[self alloc] initWithCustomView:btn];
- }
The above is the main implementation of the basic framework. There are still some shortcomings, and the gesture sliding return is not written. Promote MarkDown syntax link: http://www.jianshu.com/p/7cc9c26e8b7a Author: Damao Group Download the demo of this article: http://code.cocoachina.com/view/129999 Author: NiePlus |