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

    返回按钮部分默认是蓝色,如有两个controller,A和B,其中A跳往B。在A中有

    ViewControllerB *BVc = [[WeChatSearchViewController alloc]init];
    [self.navigationController pushViewController:BVc animated:YES];

    那么有两种方式可以修改
    ①可以在B中(不是A)的viewDidLoad或viewWillAppear写

    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

    这样只修改B界面的颜色

    ②在A中的viewWillAppear或viewDidLoad写

    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

    这种写法是全局的,会将所有由A跳往的界面的导航栏返回按钮和箭头颜色改变

    *************************** 2016-07-14 update ******************************

    如conA跳往conB,那么在conB的viewDidLoad中可以添加

    -(void)createNav{
        UIButton *navLeft = [UIButton buttonWithType:UIButtonTypeCustom];
        navLeft.size = CGSizeMake(40, 40);
        [navLeft setImage:[UIImage imageNamed:@"top_icon_back"] forState:UIControlStateNormal];
        [navLeft addTarget:self action:@selector(clickTheBackBtn) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:navLeft];
    }
    -(void)clickTheBackBtn{
        [self.navigationController popViewControllerAnimated:YES];
    }

    如若conB为webview的控制器,那么点击返回按钮事件可以这样写

    -(void)clickTheBackBtn{
        if ([self.webView canGoBack]) {
            [self.webView goBack];
        } else {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }

     效果为

    比系统自带的返回按钮看着简约

  • 相关阅读:
    字典树略解
    NOIP2018普及组初赛解题报告
    Codeforces 23A You're Given a String...
    远程消息推送的简单方法
    IOS5,6,7的新特性
    面试问题1
    IOS推送消息的步骤
    C面试问题
    label的自适应文本,让文本自适应
    TCP连接的三次握手,TCP/UDP区别联系,socket连接和http连接的区别
  • 原文地址:https://www.cnblogs.com/Apologize/p/4989130.html
Copyright © 2011-2022 走看看