UINavigationController(导航视图控制器)的基本设置

来源:互联网 发布:36氪的next网站源码 编辑:程序博客网 时间:2024/04/29 15:45

AppDelegate.m

先创建一个ViewController

MainViewController *mainVC = [[MainViewControlleralloc]init];

创建导航视图控制器(用于管理 mainVC)

UINavigationController *naVC = [[UINavigationControlleralloc]initWithRootViewController:mainVC];

self.window.rootViewController = naVC;

释放

[mainVCrelease];

[naVC release];


UINavigationController的基本设置

(1).加标题

self.title = @"猫眼儿电影";

或者

self.navigationItem.title =@"鹰王电影";




背景颜色的设置

self.navigationController.navigationBar.barTintColor = [UIColor blackColor];

注意不是所有的背景颜色都是backgroundColor



为了防止坐标系被篡改,我么办吧bar从半透明设置成不透明,这样坐标系的原点会自动向下推64

self.navigationController.navigationBar.translucent = NO;


内容方面的设置,可以指定一些视图称为titleview

UISegmentedControl *seg = [[UISegmentedControlalloc]initWithItems:@[@"信息",@"通话",@"网络"]];

self.navigationItem.titleView = seg;


创建左右两边的按钮

左边(添加的是系统自带的图标)

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCameratarget:selfaction:@selector(laftButtonAction:)]autorelease别忘了释放];


右边添加自定义图标 (阿里巴巴图标库调整为大小32 格式PNG)**********

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rigth:)];

同时

可以添加一个自己创建的Button

UIButton *button1 = [UIButtonbuttonWithType:UIButtonTypeCustom];

button1.frame =CGRectMake(0,0, 40,40);

[button1 setImage:[UIImageimageNamed:@"1.png"]forState:UIControlStateNormal];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:button1];











0 0