Tabbar switching between packages of different controllers (custom navigation + custom uiviewcontroler+ system comes with tabbar+ custom Tabbarcontroller)

Source: Internet
Author: User
Tags uikit

First, the environment for an app is very important. Both the basic functionality and the performance of later optimizations are considered.

Now many applications are not just the controller of the system, because of the complex requirements, it is necessary to customize multi-controller to manage.

Create a new Basicnavigationviewcontroller, inherit Uinavigationcontroller

Here to achieve the navigation appearance, methods and so on.

The sample code is as follows:

Then customize a basictabbarviewcontroller, inherit Uitabbarcontroller

The code is as follows:

#import <UIKit/UIKit.h>
@class Basicnavgationviewcontroller;


@interface Basictabbarviewcontroller:uitabbarcontroller

@property (nonatomic, strong) Basicnavgationviewcontroller *homenavgationcontroller;
@property (nonatomic, strong) Basicnavgationviewcontroller *minenavgationcontroller;
@property (nonatomic, strong) Basicnavgationviewcontroller *morenavgationcontroller;

@end

#import "RootViewController.h"
#import "HomeViewController.h"
#import "MineViewController.h"
#import "MoreViewController.h"
#import "BasicNavgationViewController.h"
#define Dmnavgationcolor Dmrgb (65, 109, 218)//Navigation color

#define DMRGB (R, G, b) [Uicolor colorwithred: (r)/255.f Green: (g)/255.F Blue: (b)/255.f ALPHA:1.F]

#define Dmtableviewgraycolor Dmrgb (245, 245, 249)//Bright Grey (tableview background)
@interface Basictabbarviewcontroller () <UITabBarControllerDelegate>

@end

@implementation Basictabbarviewcontroller

-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil
{
self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil];
if (self) {
}
return self;
}

-(void) didreceivememorywarning
{
[Super didreceivememorywarning];
}

-(void) viewdidload
{
[Super Viewdidload];

[Self setcustomappearance];
[Self settabbarcontroller];

}

#pragma mark-Set Tabbarcontroller
-(void) Settabbarcontroller
{
Self.delegate = self;
[Self setviewcontrollers:[self viewcontrollers]];
}

-(Nsarray *) viewcontrollers
{
Homeviewcontroller *homevc=[[homeviewcontroller Alloc]init];
Self.homenavgationcontroller = [[Basicnavgationviewcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:HOMEVC];

_homenavgationcontroller.tabbaritem = [[Uitabbaritem alloc] initwithtitle:@ "Home" Image:[uiimage imageNamed:@ "Btn_ Home _ None "] selectedimage:[uiimage imagenamed:@" Btn_ home _selected "];
_homenavgationcontroller.tabbaritem.selectedimage = [[UIImage imagenamed:@ "Btn_ home _selected"] Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];
_homenavgationcontroller.tabbaritem.tag = Dmloginsuccessbacktypehome;



Mineviewcontroller *minevc=[[mineviewcontroller Alloc]init];
Self.minenavgationcontroller = [[Basicnavgationviewcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:MINEVC];
_minenavgationcontroller.tabbaritem = [[Uitabbaritem alloc] initwithtitle:@ "My" image:[uiimage imageNamed:@ "Btn_ My _ None "] selectedimage:[uiimage imagenamed:@" Btn_ my _selected "];
_minenavgationcontroller.tabbaritem.selectedimage = [[UIImage imagenamed:@ "Btn_ my _selected"] Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];
_minenavgationcontroller.tabbaritem.tag = Dmloginsuccessbacktypemine;

Moreviewcontroller *morevc=[[moreviewcontroller Alloc]init];
Self.morenavgationcontroller = [[Basicnavgationviewcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:MOREVC];
_morenavgationcontroller.tabbaritem = [[Uitabbaritem alloc] initwithtitle:@ "More image:[uiimage imageNamed:@" Btn_ More _ None "] selectedimage:[uiimage imagenamed:@" btn_ more _selected "]
;
_morenavgationcontroller.tabbaritem.selectedimage = [[UIImage imagenamed:@ "Btn_ more _selected"] Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];
_morenavgationcontroller.tabbaritem.tag = Dmloginsuccessbacktypemore;

Return @[_homenavgationcontroller, _minenavgationcontroller, _morenavgationcontroller];

Nsarray *controllers = [Nsarray Arraywithobjects:_boutiquegoodsnavgationcontroller,_categorynavgationcontroller, _shopnavgationcontroller,_ordernavgationcontroller,_mynavgationcontroller,nil];
//
Self.viewcontrollers = controllers; can also be replaced by this
}

#pragma mark-Customize the appearance of controls
-(void) setcustomappearance
{
/* Uinavigationbar */
[[Uinavigationbar appearance] Settintcolor:[uicolor Whitecolor]];
Nsdictionary *nnormaldictionary = @{nsforegroundcolorattributename: [Uicolor Whitecolor],
Nsfontattributename:[uifont boldsystemfontofsize:18.0f]};
[[Uinavigationbar appearance] settitletextattributes:nnormaldictionary];
[[Uinavigationbar appearance] settranslucent:no];
[[Uinavigationbar appearance] setbartintcolor:dmnavgationcolor];

/* Uitarbar */
[[Uitabbar appearance] Settintcolor:[uicolor Whitecolor]];

/* Uitarbaritem */
Set the Tabbaritem font in normal state
Nsdictionary *normaldictionary = @{nsforegroundcolorattributename:dmrgb (143, 151, 175),
Nsfontattributename:[uifont systemfontofsize:10.0f]};
[[Uitabbaritem appearance] settitletextattributes:normaldictionary Forstate:uicontrolstatenormal];
Set the Tabbaritem font in the selected state
Nsdictionary *selecteddictionary = @{nsforegroundcolorattributename:dmrgb (68, 112, 224),
Nsfontattributename:[uifont systemfontofsize:10.0f]};
[[Uitabbaritem appearance] settitletextattributes:selecteddictionary forstate:uicontrolstateselected];
[[Uitabbar Appearance]setbackgroundcolor:dmtableviewgraycolor];
[Self.tabbar Setclipstobounds:yes];
}

#pragma mark-uitabbarcontrollerdelegate
-(BOOL) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Shouldselectviewcontroller: (UIViewController *) Viewcontroller
{

return YES;

}

Finally: Customize a Rootviewcontroller, inherit the Uiviewcontroller, and inherit it from the controller creation later.

Tabbar switching between packages of different controllers (custom navigation + custom uiviewcontroler+ system comes with tabbar+ custom Tabbarcontroller)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.