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 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗