1

在我的应用程序中,我添加了两个带有导航栏的 UIBarButtonItem。在iOS6及以下它看起来像这样在此处输入图像描述

但是当我在 iOS7 中运行我的应用程序时,它看起来像 在此处输入图像描述

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

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

2 回答 2

0

Try like this .... sorry i am in hurry

pragma mark my tries

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;
于 2013-10-10T12:32:34.830 回答
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];
于 2013-10-11T11:53:38.627 回答