iOS UIBarButtonItem对齐

时间:2013-10-10 10:32:26

标签: iphone ios objective-c ios6 ios7

在我的应用程序中,我添加了两个带导航栏的UIBarButtonItem。在iOS6及更低版本中,它看起来像enter image description here

但是当我在iOS7中运行我的应用程序时,它看起来像 enter image description here

问题是:刷新按钮下降。所以请帮我显示等于'今天'按钮的刷新按钮。以下是我正在使用的代码,

 UIBarButtonItem* todayButton = [[UIBarButtonItem alloc] initWithTitle:@"Today"
                                                                style:UIBarButtonItemStyleBordered 
                                                               target:self
                                                               action:@selector(showTodayAction:)];
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                                              target:self
                                                                              action:@selector(refreshAction:)];
refreshButton.style = UIBarButtonItemStyleBordered;

    UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                       target:nil
                                                                                       action:nil];
    negativeSeperator.width = -12;

    TransparentToolbar *toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, -5, 100, TOOLBAR_HEIGHT)];
    toolbar.items = [NSArray arrayWithObjects:
                     negativeSeperator,
                     refreshButton, todayButton,
                     negativeSeperator,
                     nil];

    UIView *toolbarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, TOOLBAR_HEIGHT)];
    [toolbarView addSubview:toolbar];

    UIBarButtonItem *toolbarItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarView];

    self.navigationItem.leftBarButtonItem = toolbarItem;

2 个答案:

答案 0 :(得分:0)

试试这样......对不起,我很着急

pragma标记我的尝试

UIBarButtonItem* todayButton = [[UIBarButtonItem alloc] initWithTitle:@"Today"
                                                                style:UIBarButtonSystemItemRefresh
                                                               target:self
                                                               action:@selector(goBack)];
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                                               target:self
                                                                               action:@selector(goBack)];
refreshButton.style = UIBarButtonItemStyleBordered;

UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                   target:nil
                                                                                   action:nil];
negativeSeperator.width = -12;

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
toolbar.items = [NSArray arrayWithObjects:

                 negativeSeperator,refreshButton, todayButton,
                 negativeSeperator,
                 nil];//
 self.navigationItem.leftBarButtonItems = toolbar.items;

答案 1 :(得分:0)

我认为不需要其他额外的观点,以下代码将完成您的工作:

UIBarButtonItem* todayButton = [[UIBarButtonItem alloc] initWithTitle:@"Today"
                                                                    style:UIBarButtonItemStyleBordered
                                                                   target:self
                                                                   action:@selector(showTodayAction:)];
    UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                                                   target:self
                                                                                   action:@selector(refreshAction:)];
    refreshButton.style = UIBarButtonItemStyleBordered;

    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:refreshButton, todayButton, nil];