问题
In my app I added two UIBarButtonItem with navigation bar. In iOS6 and below it looks like this

But when I run my app in iOS7 it looks like

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;
回答1:
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;
回答2:
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];
来源:https://stackoverflow.com/questions/19293363/ios-uibarbuttonitem-alignments