大多数ios应用都是以标签栏加导航栏的形式呈现,一般根控制器都是UIToolbar,然后再以UINavigationController为子控制器,然后再加入UIViewController。为什么要这样?因为不同的标签栏的项一般对应不
同的功能,那么导航栏的标题一般就不同。如果所有导航栏都一样,那你就随便设置根控制器。
主要代码: AppDelegate.h中
@class cscControllerOne;
@class cscControllerTwo;
@class cscControllerThree;
@class cscControllerFour;
@interface cscAppDelegate : UIResponder {
cscControllerOne *oneRootView;
cscControllerTwo *twoRootView;
cscControllerThree *threeRootView;
cscControllerFour
*fourRootView;
UITabBarController *tabBarController;
UINavigationController *unc1;
UINavigationController *unc2;
UINavigationController *unc3;
UINavigationController *unc4;
}
AppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp
tions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
oneRootView=[[cscControllerOne alloc]init];
oneRootView.title=@"视图1";
twoRootView=[[cscControllerTwo alloc]init];
twoRootView.title=@"视图2";
threeRootView=[[cscControllerThree alloc]init];
threeRootView.title=@"视图3";
fourRootView=[[cscControllerFour alloc]init];
fourRootView.title=@"视图4";
unc1=[[UINavigationController alloc]initWithRootViewControll
er:oneRootView];
unc2=[[UINavigationController alloc]initWithRootViewControll
er:twoRootView];
unc3=[[UINavigationController alloc]initWithRootViewControll
er:threeRootView];
unc4=[[UINavigationController alloc]initWithRootViewControll
er:fourRootView];
unc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"淘宝搜索" image:[UIImage imageNamed:@"Area.png"]
tag:2];
unc2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的淘宝" image:[UIImage imageNamed:@"Summary.png"]
tag:3];
unc3.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"淘宝功能" image:[UIImage imageNamed:@"Apple.png"]
tag:4];
unc4.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"软件设置" image:[UIImage imageNamed:@"BoxVolume.png"]
tag:5];
NSArray *viewsArray=[[NSArray alloc]initWithObjects:unc1,unc2,unc3,unc4, nil];
tabBarController=[[UITabBarController alloc]init];
tabBarController.viewControllers=viewsArray;
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
可能这段代码并不难,刚入门的新手都能轻松做出来,但是一个新手与一个有多年开发经验的高手,区别之一在于代码的积累,所以大量的案例,是一个高手的必备,是二次开发的利器。
下载地址http://www.kuaipan.cn/file/id_30491149655343756.htm
有时候可能会遇到在push之后隐藏标签栏,其实很简单,只要一条语句:
self.hidesBottomBarWhenPushed
=NO;
下载一个push隐藏的例子
效果图:
效果图二:图中第二到第五张图是iphone5真机中的效果,自定义标签栏,万能的方法。
有自定义的标签栏,自定义的导航栏,隐藏标签栏,隐藏导航栏,并且不阻塞viewWillAppear,自定义导航栏的返回按钮
具体办法是隐藏系统自带的标签栏,绘制自己的标签栏,然后为每个标签设置点击事件。
self.customTabBar = [[[CustomTabBar alloc] init] autorelease];
self.customTabBar.tabBarController = self.viewController;
[self.customTabBar custom];
[self.viewController.tabBarController.tabBar setHidden:YES];
自定义一个按钮,然后加到导航栏中,可以是替换系统的返回按钮
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(0, 0, 60, 30);
[btn setBackgroundImage:[UIImage imageNamed:@"按钮p.png"] forState:UIControlStateNormal];
//
[btn setTitle:@"aaaaaa" forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"按钮n.png"] forState:UIControlStateHighlighte
d];
// highlighted
[btn addTarget:self action:@selector(pushAction) forControlEvents:UIControlEventTouchUpIns
ide];
UIBarButtonItem *BarBtn = [[UIBarButtonItem alloc] initWithCustomView:btn ];
self.navigationItem.leftBarButtonItem=BarBtn;
[BarBtn release];
[btn release];
设置系统样式UIBarButtonItem按钮
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"button" style:UIBarButtonItemStyleBord
ered target:self action:@selector(Action)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
设置一个包含自定义图标的UIBarButtonItem按钮
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"email.png"] style:UIBarButtonItemStyleBord
ered target:self action:@selector(action:)];
self.navigationItem.rightBarButtonItem = addButton;
设置一个分段控件替换导航栏上的按钮
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems: [NSArray arrayWithObjects: [UIImage imageNamed:@"up.png"], [UIImage imageNamed:@"down.png"], nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChang
ed];
segmentedControl.frame = CGRectMake(0, 0, 90, kCustomButtonHeight);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleB
ar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
中间第二个标签有一个远较,是因为那部分图片是透明的,根据需要可以设置标签栏的样式。
点击下载http://www.kuaipan.cn/file/id_30491149655345680.htm
设置导航栏为半透明
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTra
nslucent;
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTransluce
nt;
设置导航栏为透明
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpa
que;
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
设置导航栏为默认
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
设置一个分段控件替换标题视图
NSArray *segmentTextContent = [NSArray arrayWithObjects: NSLocalizedString(@"Image", @""), NSLocalizedString(@"Text", @""), NSLocalizedString(@"Video", @""), nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexib
leWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleB
ar;
segmentedControl.frame = CGRectMake(0, 0, 400, kCustomButtonHeight);
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChang
ed];
self.navigationItem.titleView = segmentedControl;
[segmentedControl release];
判断选中事件
UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
NSLog(@"Segment clicked: %d", segmentedControl.selectedSegmentIndex);
在导航栏上显示一行字
self.navigationItem.prompt = NSLocalizedString(@"Please select the appropriate media type:", @"Page Five Prompt");
主要代码: AppDelegate.h中
@class cscControllerOne;
@class cscControllerTwo;
@class cscControllerThree;
@class cscControllerFour;
@interface cscAppDelegate : UIResponder {
}
AppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp
{
}
可能这段代码并不难,刚入门的新手都能轻松做出来,但是一个新手与一个有多年开发经验的高手,区别之一在于代码的积累,所以大量的案例,是一个高手的必备,是二次开发的利器。
下载地址http://www.kuaipan.cn/file/id_30491149655343756.htm
有时候可能会遇到在push之后隐藏标签栏,其实很简单,只要一条语句:
self.hidesBottomBarWhenPushed
下载一个push隐藏的例子
效果图:





效果图二:图中第二到第五张图是iphone5真机中的效果,自定义标签栏,万能的方法。
有自定义的标签栏,自定义的导航栏,隐藏标签栏,隐藏导航栏,并且不阻塞viewWillAppear,自定义导航栏的返回按钮
自定义一个按钮,然后加到导航栏中,可以是替换系统的返回按钮
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
//
设置系统样式UIBarButtonItem按钮
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"button" style:UIBarButtonItemStyleBord
设置一个包含自定义图标的UIBarButtonItem按钮
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"email.png"] style:UIBarButtonItemStyleBord
self.navigationItem.rightBarButtonItem = addButton;
设置一个分段控件替换导航栏上的按钮
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems: [NSArray arrayWithObjects: [UIImage imageNamed:@"up.png"], [UIImage imageNamed:@"down.png"], nil]];
中间第二个标签有一个远较,是因为那部分图片是透明的,根据需要可以设置标签栏的样式。
点击下载http://www.kuaipan.cn/file/id_30491149655345680.htm
设置导航栏为半透明
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTra
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTransluce
设置导航栏为透明
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpa
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
设置导航栏为默认
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
设置一个分段控件替换标题视图
NSArray *segmentTextContent = [NSArray arrayWithObjects: NSLocalizedString(@"Image", @""), NSLocalizedString(@"Text", @""), NSLocalizedString(@"Video", @""), nil];
判断选中事件
UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
在导航栏上显示一行字
self.navigationItem.prompt = NSLocalizedString(@"Please select the appropriate media type:", @"Page Five Prompt");
弹出式菜单栏的做法,其实就是自定义view;然后以某一个视图为根视图,进行其它操作。首先是uiview,uiview中加入scrollview,一般情况下是
scrollview无法滑动,但是加入一个方法之后就可以了
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {