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/-

  • 相关阅读:
    android 设置时间和日期
    android 对话框
    android notification 通知
    android 动画(转载)
    js的作用域题
    js高级
    js中级6
    js中级小知识5
    js中级小知识4
    js中级小知识3
  • 原文地址:https://www.cnblogs.com/FightingLuoYin/p/4618373.html
Copyright © 2011-2022 走看看