导航栏左栏按钮中的栏按钮项目粘在左上角的 conrner [英] Barbutton item in navigtion bar leftbar button got stick to the top left conrner

查看:34
本文介绍了导航栏左栏按钮中的栏按钮项目粘在左上角的 conrner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

条形按钮的 y 原点为 0 到导航栏,x 为 0.但我想为条形按钮项添加一些 y 位置.

bar button got stick to the y origin as 0 to navigation bar and x as 0.but i want to add some y position to barbutton item.

 UIBarButtonItem *barbutton;

            barbutton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(onbackbtnpressed:)];
            [barbutton setWidth:30];
            [barbutton setTintColor:KANEKA_BLUE_COLOR];
            [barbutton setAccessibilityFrame:CGRectMake(10, 10, 30, 20)];
            self.navigationItem.leftBarButtonItem = barbutton;

请告诉我如何设置栏按钮框架或如何设置栏按钮 y 位置.

Please tell me how can i set the barbutton frame or how to set the bar button y position.

推荐答案

我对这个问题的看法 - 根据 iOS Human Interface Guidelines,不建议为导航栏上的栏按钮项添加 y 间距.

My views about this question - As per iOS Human Interface Guidelines it is not recommended to add y spacing for the bar button items on navigation bar.

我们可以通过设置导航项的按钮数组来更新x定位,如下所示:

We can update x positioning by setting an array of buttons for navigation item as shown below:

  UIBarButtonItem *fixedSpaceBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  [fixedSpaceBarButton setWidth:10];

  UIBarButtonItem *barbutton;

  barbutton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(onbackbtnpressed:)];
  [barbutton setWidth:30];
  [barbutton setTintColor:[UIColor redColor]];
  [barbutton setAccessibilityFrame:CGRectMake(10, 10, 30, 20)];

  self.navigationItem.leftBarButtonItems = [NSArray
                                            arrayWithObjects:fixedSpaceBarButton, barbutton, nil];

这篇关于导航栏左栏按钮中的栏按钮项目粘在左上角的 conrner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆