导航条(Navigation Bar)
导航条上添加按钮:拖入bar button Item控件到Navigation Bar控件上
使用:
1.添加事件:
bar button Item控件只有一个事件
-(IBAction)click:(id)sender;
2.为bar button Item加载图片
-(IBAction)click:(id)sender
{
sender.image=[UIImage imageNamed:"1.png"];//.png格式可省略后缀,直接写1
}
3.添加返回按钮
UINavigationItem *item = [nBar.items objectAtIndex:0];
UINavigationItem *back = [[UINavigationItem alloc] initWithTitle:@"Back"];
NSArray *items = [[NSArray alloc] initWithObjects:back,item,nil];
[nBar setItems:items];
//单击back按钮处理函数
- (BOOL)navigationBar:(UINavigationBar *)navigationBar
shouldPopItem:(UINavigationItem *)item
{
[self dismissModalViewControllerAnimated:YES]; //返回主页面
return FALSE;
}
4.设置NavigationBar位置大小
UINavigationBar* m_nBar;
[m_nBar setFrame:CGRectMake(0,0, self.view.frame.size.width, 217.0)];
5.添加背景图片
UIImageView *imageView = [[[UIImageView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 217.0f)]autorelease];
imageView.image = [UIImage imageNamed: @"nabar_Background.png"];
[m_nBar addSubview: imageView];
6.设置样式
[navBar setBarStyle:UIBarStyleDefault];
//UIBarStyleDefault:默认样式
//UIBarStyleBlack:黑色
//UIBarStyleBlackOpaque:黑色不透明
//UIBarStyleBlackTranslucent:黑色透明
//初始化
UINavigationBar *m_pikbar=nil;
m_pikbar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 50.0)];
[navBar setTranslucent:YES];用来指示是否透明。
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"截取",nil)
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done:)];
导航条上添加按钮:拖入bar button Item控件到Navigation Bar控件上
使用:
1.添加事件:
bar button Item控件只有一个事件
-(IBAction)click:(id)sender;
2.为bar button Item加载图片
-(IBAction)click:(id)sender
{
sender.image=[UIImage imageNamed:"1.png"];//.png格式可省略后缀,直接写1
}
3.添加返回按钮
UINavigationItem *item = [nBar.items objectAtIndex:0];
UINavigationItem *back = [[UINavigationItem alloc] initWithTitle:@"Back"];
NSArray *items = [[NSArray alloc] initWithObjects:back,item,nil];
[nBar setItems:items];
//单击back按钮处理函数
- (BOOL)navigationBar:(UINavigationBar *)navigationBar
shouldPopItem:(UINavigationItem *)item
{
[self dismissModalViewControllerAnimated:YES]; //返回主页面
return FALSE;
}
4.设置NavigationBar位置大小
UINavigationBar* m_nBar;
[m_nBar setFrame:CGRectMake(0,0, self.view.frame.size.width, 217.0)];
5.添加背景图片
UIImageView *imageView = [[[UIImageView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 217.0f)]autorelease];
imageView.image = [UIImage imageNamed: @"nabar_Background.png"];
[m_nBar addSubview: imageView];
6.设置样式
[navBar setBarStyle:UIBarStyleDefault];
//UIBarStyleDefault:默认样式
//UIBarStyleBlack:黑色
//UIBarStyleBlackOpaque:黑色不透明
//UIBarStyleBlackTranslucent:黑色透明
//初始化
UINavigationBar *m_pikbar=nil;
m_pikbar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 50.0)];
[navBar setTranslucent:YES];用来指示是否透明。
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"截取",nil)
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done:)];