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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大