zoukankan      html  css  js  c++  java
  • ios之自定义导航栏上的返回按钮

    导航栏的按钮,右边的按钮是可以自己随意添加的。但左边的返回按钮怎么定制?你会说,添加一个自己的按钮呗!你可以试试看,这样行不行。

    正确的答案是重载UINavigationController类的pushViewController:animated方法。

    #import <UIKit/UIKit.h>

    @interface MyNavigationController: UINavigationController {

    }

    @end

     

    #import "MyNavigationController.h"

     

    @implementation MyNavigationController

    -(void)popself

    {

        [self popViewControllerAnimated:YES];

    }

    -(UIBarButtonItem*) createBackButton

    return [[UIBarButtonItem alloc]

    initWithTitle:@"返回"

    style:UIBarButtonItemStyleBordered

    target:self

    action:@selector(popself)];

    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated 

        [super pushViewController:viewControlleranimated:animated]; 

    if (viewController.navigationItem.leftBarButtonItem== nil && [self.viewControllers count] > 1) { 

            viewController.navigationItem.leftBarButtonItem =[self createBackButton];

        } 

    @end

     

    使用MyNavigationController替换UINavigationController。或者直接创建一个UINavigationController的新类别

  • 相关阅读:
    第03组 Beta冲刺(1/4)
    第03组 Alpha事后诸葛亮
    第03组 Alpha冲刺(4/4)
    第03组 Alpha冲刺(3/4)
    第03组 Alpha(2/4)
    第03组 Alpha冲刺(1/4)
    第03组团队Git现场编程实战
    第二次结对编程作业
    团队项目-需求分析报告
    第01组 Beta冲刺(3/5)
  • 原文地址:https://www.cnblogs.com/yulang314/p/3550496.html
Copyright © 2011-2022 走看看