在UINavigationBar的子类中设置backButton框架

问题描述:

对于使用ARC的iOS 5.0中的iPad,我使用UINavigationBar的子类来制作具有更宽条形的自定义导航栏..此导航栏上的后退按钮需要垂直居中,因为我使用更宽的后退按钮。现在,它在自然的地方拥抱底部。我知道我可以在每个视图控制器的viewDidLoad方法上使用UINavigationItem来重新调整它。在UINavigationBar的子类中设置backButton框架

但是,是否有可能抢回我创建的UINavigationBar的自定义子类中的按钮,以便我可以使用layoutSubviews将其置于垂直居中?

在此先感谢您的帮助。

你试过:

navigationBar.backItem.leftBarButtonItem 
+0

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

请试试这个,我觉得这可能会帮助你

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