Navigation Bar

导航条(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:)];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值