2013-10-10 90 views
1

在我的應用程序中,我添加了兩個導航欄的UIBarButtonItem。在iOS6的和它下面看起來像這樣enter image description hereiOS UIBarButtonItem對齊

但是當我在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; 
+0

你能看到這個問題http://stackoverflow.com/questions/18861201/uibar buttonitem-with-custom-view-not-aligned-on-ios-7-when-left-left-left –

+0

@megan你有解決方案....? – Spynet

+0

@Spynet尚未... – Megan

回答

0

嘗試這樣的....對不起,我在趕時間

編譯標誌我嘗試

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; 
+0

對不起,我很着急,我會稍後解釋.... – Spynet

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