码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 自定义UINavigationController返回按钮

时间:2015-07-03 14:00:11      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:

主要代码如下:

//自定义导航栏返回按钮
    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/-

 

iOS 自定义UINavigationController返回按钮

标签:

原文地址:http://www.cnblogs.com/FightingLuoYin/p/4618373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!