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

     效果为

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

  • 相关阅读:
    MVC身份验证及权限管理
    EasyPR--开发详解
    ASP.NET 安全认证
    将Excel导入到数据中
    ExtJS 4 树
    ExtJS 4 表单
    ExtJS 4 Grids 详解
    ExtJS 4 类系统
    第4章 类型基础 -- 4.1 所有类型都从System.Object派生
    随滚动条浮动的链接块层
  • 原文地址:https://www.cnblogs.com/Apologize/p/4989130.html
Copyright © 2011-2022 走看看