【问题标题】:Setting the backButton frame in a subclass of UINavigationBar在 UINavigationBar 的子类中设置 backButton 框架
【发布时间】:2012-04-20 05:17:30
【问题描述】:

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

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

在此先感谢您的帮助。

【问题讨论】:

    标签: ios ipad uinavigationbar


    【解决方案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];
    

    【讨论】:

      【解决方案2】:

      你试过了吗:

       navigationBar.backItem.leftBarButtonItem
      

      【讨论】:

      • 谢谢,可能需要使用 backitem 或 topitem 。但是,仍然无法到达框架来修改它.. 或重新定位它
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-01
      • 2010-12-24
      • 1970-01-01
      • 2010-10-13
      • 1970-01-01
      相关资源
      最近更新 更多