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

iOS7以后处理leftBarButtonItem问题

时间:2015-10-21 12:20:07      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

因为ios7以后leftBarButtonItem往右移了大概10px,现在要使得leftBarItem和ios7之前那样显示,处理如下:

if (isBeforeIOS7)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(15,5,22,22);
        [btn setBackgroundImage:[UIImage imageNamed:@"icon_back_left"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(goBackAction) forControlEvents: UIControlEventTouchUpInside];
        UIBarButtonItem*backBarBtn=[[UIBarButtonItem alloc]initWithCustomView:btn];
        self.navigationItem.leftBarButtonItem=backBarBtn;
    }
    else
    {
        UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back_left"] style:UIBarButtonItemStyleDone target:self action:@selector(goBackAction)];
        UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        negativeSpacer.width = -10;
        self.navigationItem.leftBarButtonItems = @[negativeSpacer,backBarBtn];
    }

 

iOS7以后处理leftBarButtonItem问题

标签:

原文地址:http://www.cnblogs.com/liaods/p/4897323.html

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