【问题标题】:how to add two button in navigation bar with some space如何在导航栏中添加两个按钮并留出一些空间
【发布时间】:2013-02-28 05:51:04
【问题描述】:

我在导航栏中添加了两个按钮,它们工作正常,但我希望它们之间有空间,它们都结合在一起,我希望它们之间有一点空间

  UIBarButtonItem *btnAdd = [[UIBarButtonItem alloc] initWithTitle:@"Add"
                                                           style:UIBarButtonItemStylePlain
                                                          target:self
                                                          action:@selector(Add)];

UIBarButtonItem *btnEdit = [[UIBarButtonItem alloc] initWithTitle:@"Add"
                                                           style:UIBarButtonItemStylePlain
                                                          target:self
                                                          action:@selector(Add)];


UIToolbar *rightToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
rightToolBar.backgroundColor = [UIColor clearColor];
rightToolBar.tintColor = [UIColor colorWithRed:40.0/255.0 green:48.0/255.0 blue:51.0/255.0 alpha:0.0];
NSArray *buttonsRight = [NSArray arrayWithObjects:btnEdit, btnAdd, nil];
[rightToolBar setItems:buttonsRight];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightToolBar];     

【问题讨论】:

    标签: ipad uibutton uinavigationbar


    【解决方案1】:

    您可以在UIBarButtonItem 之间添加这两个中的任何一个

    UIBarButtonItem *fixed = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]
    
    UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]
    

    注意要设置固定空间UIBarButtonItem的宽度,需要设置.width属性

    [fixed setWidth:455.0f];
    

    【讨论】:

    • 我已经这样做了,但没有间距,我想要一个在右侧,一个在右侧有 30 像素的空间
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 2017-02-06
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多