• 自定义NavgationBa返回按钮



    iOS  上UINavigationController视图压栈形式,可以在当前视图无限制push许多视图,然而一些会觉得自带的push按钮不够美观,而且当上的上一个页面title很长的时候,那个返回按钮就很长,怎样定义一个自己返回按钮呢?像第三幅图片一样。。。


      



    需要push的视图里面定义一个事件

    - (IBAction)pushVC:(id)sender {
        NavViewController *navVC = (NavViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"NavViewController"];
        navVC.title = NSLocalizedString(@"设置", nil);
        [self.navigationController pushViewController:navVC animated:YES];
    }


    替换返回按钮,定义自定义按钮

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        backBtn.frame = CGRectMake(0, 0, 44, 44);
        
        [backBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
        [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
        
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
        self.navigationItem.leftBarButtonItem = backItem;
         
    	// Do any additional setup after loading the view.
    }
    
    -(void)doBack:(id)sender
    {
        [self.navigationController popViewControllerAnimated:YES];
    }


    源码下载地址:https://github.com/XFZLDXF/XFNavBarBtn



    原创博客欢迎转载分享,请注明出处http://blog.csdn.net/duxinfeng2010


  • 相关阅读:
    魔术方法之__call与__callStatic方法
    thinkphp5 实现搜索分页能下一页保留搜索条件
    koa2
    mongodb
    nodejs
    小程序
    Vue学习
    js4
    扎心!来自互联网er的2019年度总结,看完笑着流泪……
    谈谈“奋斗逼!”
  • 原文地址:https://www.cnblogs.com/riskyer/p/3271476.html
Copyright © 2020-2023  润新知