2012-04-20 38 views
0

對於使用ARC的iOS 5.0中的iPad,我使用UINavigationBar的子類來製作具有更寬條形的自定義導航欄..此導航欄上的後退按鈕需要垂直居中,因爲我使用更寬的後退按鈕。現在,它在自然的地方擁抱底部。我知道我可以在每個視圖控制器的viewDidLoad方法上使用UINavigationItem來重新調整它。在UINavigationBar的子類中設置backButton框架

但是,是否有可能搶回我創建的UINavigationBar的自定義子類中的按鈕,以便我可以使用layoutSubviews將其置於垂直居中?

在此先感謝您的幫助。

回答

0

你試過:

navigationBar.backItem.leftBarButtonItem 
+0

謝謝,可能需要使用backitem或topitem。然而,仍然無法到達框架來修改它或重新定位它 – inforeqd 2012-04-20 06:04:49

1

請試試這個,我覺得這可能會幫助你

// image for my back button 
UIImage *backButtonImage= [UIImage imageNamed:@"Back.png"]; 
UIButton *leftBarButton = [UIButton buttonWithType: UIButtonTypeCustom]; 

// Setting the image for the back button 
[leftBarButton setBackgroundImage: backButtonImage forState:UIControlStateNormal]; 
[leftBarButton addTarget: self action:@selector(backToMenu:) forControlEvents:UIControlEventTouchUpInside]; 

// setting the frame for the back button 
leftBarButton.frame = CGRectMake(0, 0, 65, 32); 

// setting the custom button to navigationbars back button 
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: leftBarButton];