您的位置:首页 > 产品设计 > UI/UE

UINavigationController, UITabBarController

2016-03-13 12:23 435 查看

UITabBarController

通用

AppDelegate.m

self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];

ViewController *vc = [[ViewController alloc] init];
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:vc];
// 创建 TabBar 按钮的样式
naVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1000];

SecondViewController *secVC = [[SecondViewController alloc] init];
UINavigationController *secNAVC = [[UINavigationController alloc] initWithRootViewController:secVC];
secNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"shop" image:[UIImage imageNamed:@"1.png"] selectedImage:[UIImage imageNamed:@"2.png"]];

// 创建 tabBarController
UITabBarController *tab = [[UITabBarController alloc] init];
tab.viewControllers = @[naVC, secNAVC, ...];
// 给 window 设置根视图控制器
self.window.rootViewController = tab;

// 编程的时候, 设置默认的出现页面,不用每次都从第0个开始
tab.selectedIndex = 3;

tab.delegate = self;

[tab release];
[naVC release];
[vc release];


property

naVC.tabBarItem.badgeValue
小红点的内容, 无小红点时为 nil

naVC.tabBarItem
创建 tabBar 按钮的样式

eg.

naVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1000];
或者
naVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"shop" image:[UIImage imageNamed:@"1.png"] selectedImage:[UIImage imageNamed:@"2.png"]];


UITabBarController的外观设置

tabBar.translucent
透明

tabBar.barTintColor
背景颜色

tabBar.tintColor
图标被选中时颜色

selectedIndex
默认出现的页面编号

protocol

-(void) tabBarController: (UITabBarController * )tabBarController didSelectViewController:(UIViewController * )viewController

UINavigationController

通用

AppDelegate.m

#import "ViewController.h"

self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
[_window release];
ViewController *vc = [[ViewController alloc] init];
// 创建导航视图控制器
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:vc];
// 把导航视图控制器设置成window的视图控制器
self.window.rootViewController = naVC;
[naVC release];
[vc release];
return YES;
}

- (void)dealloc
{
[_window release];
[super dealloc];
}


设置外观

self.navigationItem.title = @"导航栏标题";


property

navigationController.navigationBar.translucent
影响坐标系的起点:默认 半透明YES(0, 0), 不透明NO(0, 64)


navigationController.navigationBar.barTintColor
背景颜色


navigationItem.title
标题


navigationItem.titleView
标题可以用视图代替


navigationItem.leftBarButtonItem(s)
创建左右两边的按钮(们)


navigationItem.rightBarButtonItem

// 创建系统自带的按钮
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(barAction:)] autorelease];

// 模态跳转 view往secondView跳转
- (void) buttonAction:(UIButton *) button {
SecondViewController *loginVC = [[SecondViewController alloc] init];
[secVC setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[self presentViewController: secVC animated:YES completion:^{

}];
}
// 按钮用自定义的图片,图片颜色固定是蓝色
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(commentAction:)];
// 用自定义视图创建按钮,让图片编程原来的颜色
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
myButton.frame = CGRectMake(0, 0, 40, 40);
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView: button] autorelease];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: