garaster 2012-09-21 02:40 采纳率: 0%
浏览 3283
已结题

怎样能实现像我图中那样的导航的button

我想创建一个像下面图的导航条navigationBar :

the picture

我知道可以使用UIButton代替导航条中间的标题,但是能不能弄成像这张图片这样的?

如上图,在导航条中有三个不同的button,怎么在iphone中实现这样的效果?

  • 写回答

2条回答

  • MrsSeven7 2012-09-21 05:44
    关注

    如果用UINavigationController:
    1.改变导航条背景图:

    [self.navigationController.navigationBar setBackgroundImageForBarMetrics:] 
    

    2.左右button的设置:

    [self.navigationItem setLeftBarButtonItem:],[self.navigationItem setRightBarButtonItem:] 
    

    需要去掉边框。

    3.设置中间的三个button:

    UIView *buttonView= [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 40)];
    UIButton *button1= [UIButton buttonWithType:UIButtonTypeCustom];
    button1.imageView.image= [UIImage imageNamed:@"button1.png"];
    button1.frame= CGRectMake(0, 0, 40, 40);
    UIButton *button2= [UIButton buttonWithType:UIButtonTypeCustom];
    button2.imageView.image= [UIImage imageNamed:@"button2.png"];
    button2.frame= CGRectMake(70, 0, 40, 40);
    UIButton *button3= [UIButton buttonWithType:UIButtonTypeCustom];
    button3.imageView.image= [UIImage imageNamed:@"button3.png"];
    button3.frame= CGRectMake(140, 0, 40, 40);
    [buttonView addSubview:button1];
    [buttonView addSubview:button2];
    [buttonView addSubview:button3];
    self.navigationItem.titleView= buttonView;
    

    大小自己调。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services