导航栏中的栏按钮项左边栏按钮粘在左上角的康纳上



bar 按钮粘在 y 原点上,因为导航栏是 0,x 是 0.但我想在栏按钮项目上添加一些 y 位置。

 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 位置。

实际上,

我已经设法以稍微不同的方式设置了y原点,这可能是一个很大的过程,但它非常好。

我在视图控制器中添加了一个工具栏并设置了栏按钮项并隐藏了导航栏。它适用于所有弹出框控制器。

self.toolbar.hidden = NO;
        self.contentSizeForViewInPopover = CGSizeMake(self.view.frame.size.width-100,self.view.frame.size.height-100);
        self.navigationController.navigationBarHidden = YES;
        [self.toolbar setTintColor:KANEKA_BLUE_COLOR];
        [self.backbutton setTintColor:KANEKA_BLUE_COLOR];

我对这个问题的看法 - 根据 iOS 人机界面指南,不建议为导航栏上的栏按钮项添加 y 间距。

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

  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];

最新更新