首页 > 移动平台 > 详细

iOS 自定义UINavigationController返回按钮

时间:2015-07-03 13:57:34      阅读:332      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!