1

In my app I added two UIBarButtonItem with navigation bar. In iOS6 and below it looks like this enter image description here

But when I run my app in iOS7 it looks like enter image description here

issue is: refresh button goes down. So please help me to display refresh button equal to 'today' button. Below is the code I'm using ,

 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;
Cœur
  • 37,241
  • 25
  • 195
  • 267
Megan
  • 107
  • 1
  • 1
  • 8

2 Answers2

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;
Community
  • 1
  • 1
Arun
  • 3,406
  • 4
  • 30
  • 55
0

I think there is no requirement of other extra views, the following code will do your work :

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];
Yuvrajsinh
  • 4,536
  • 1
  • 18
  • 32