ios - 在 UINavigationBar 的子类中设置 backButton 框架

标签 ios ipad uinavigationbar

对于使用 ARC 的 iOS 5.0 中的 iPad,我使用 UINavigationBar 的子类来制作具有更宽栏的自定义导航栏。此导航栏上的后退按钮需要垂直居中因为我使用的是更宽的后退按钮。现在,它在自然位置拥抱底部。我知道我可以使用每个 View Controller 的 viewDidLoad 方法上的 UINavigationItem 将其重新定位。

但是,是否可以在我创建的 UINavigationBar 的自定义子类中获取后退按钮,以便我可以使用layoutSubviews 将其垂直居中布局?

预先感谢您对此提供的帮助。

最佳答案

请尝试一下,我想这可能对你有帮助

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

关于ios - 在 UINavigationBar 的子类中设置 backButton 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10240660/

相关文章:

iphone - Xcode 5 部署目标仅限于 iOS 7

iphone - 如何在 iPhone 中获取应用程序安装时间

ios - 自定义 iOS UINavigationBar/UITabBar 和移除 Tint Colors

ios - iOS 自定义披露指标有哪些维度?

ios - 如何在 AlertView 中添加 UIActivityIndi​​catorView

jquery - 云轮播和 iPad/iPhone 触摸事件

ios 半透明导航栏但实心导航栏按钮

ios - SceneKit:zFar 或 Far Clipping 值会影响定向光及其阴影吗?

ios - UIBezierPath bezierPathWithArcCenter 未正确居中

ios - 使用 uinavigationcontroller 时的全屏背景图像