zoukankan      html  css  js  c++  java
  • iOS 自定义UINavigationController返回按钮

    主要代码如下:

    //自定义导航栏返回按钮
        self.navigationItem.leftBarButtonItem = ({
            
            //导航栏返回背景视图
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 44)];
            
            //返回按钮
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 12, 20, 20)];
            [button setBackgroundImage:[UIImage imageNamed:@"goBack"]
                              forState:UIControlStateNormal];
            [button addTarget:self
                       action:@selector(backTo:)
             forControlEvents:UIControlEventTouchDown];
            button.imageView.contentMode = UIViewContentModeScaleAspectFit;
            [view addSubview:button];
            
            //中间分割线
            UIView *seprateLine = ({
                UIView *view = [[UIView alloc]initWithFrame:CGRectMake(30, 12, 1, 20)];
                view.backgroundColor = [UIColor colorWithRed:45/255.0 green:45/255.0 blue:45/255.0 alpha:1];
                view;
            });
            [view addSubview:seprateLine];
            
            //显示返回标题
            UILabel *backLabel = ({
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 100, 44)];
                label.textAlignment = NSTextAlignmentLeft;
                label.font = [UIFont systemFontOfSize:14];
                label.textColor = [UIColor blackColor];
                label.text = @"ViewController";
                label;
            });
            [view addSubview:backLabel];
            
            //把view添加上去
            UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]
                                              initWithCustomView:view];
            barButtonItem;
        });
    

     Demo代码下载:https://github.com/LuoDaRen/-

  • 相关阅读:
    python学习第18天----属性、类方法、静态方法
    面试总结
    JAVA面试题整理
    Docker-基础
    Shell
    MYSQL
    logstash的使用(ELK)
    (ELK)FileBeat的使用
    Zookeeper的介绍和单机、集群搭建
    Elaticsearch7.7.0的安装(ELK)
  • 原文地址:https://www.cnblogs.com/FightingLuoYin/p/4618373.html
Copyright © 2011-2022 走看看