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

iOS7 UI兼容 导航栏按钮边距

时间:2014-05-17 23:53:48      阅读:498      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   java   

iOS7之前的UI为:

bubuko.com,布布扣

而在iOS7中,由于设计方面的原因,使得UI变为:

bubuko.com,布布扣

 

修改的方法重写UINavigationItemsetLeftBarButtonItemsetRightBarButtonItem方法,使之与之前版本兼容;

代码如下:

bubuko.com,布布扣
@interface UINavigationItem (margin)

@end
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
@implementation UINavigationItem (margin)

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
- (void)setLeftBarButtonItem:(UIBarButtonItem *)_leftBarButtonItem
{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
    {
        UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        negativeSeperator.width = -12;
        
        if (_leftBarButtonItem)
        {
            [self setLeftBarButtonItems:@[negativeSeperator, _leftBarButtonItem]];
        }
        else
        {
            [self setLeftBarButtonItems:@[negativeSeperator]];
        }
        [negativeSeperator release];
    }
    else
    {
        [self setLeftBarButtonItem:_leftBarButtonItem animated:NO];
    }
}

- (void)setRightBarButtonItem:(UIBarButtonItem *)_rightBarButtonItem
{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
    {
        UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        negativeSeperator.width = -12;
        
        if (_rightBarButtonItem)
        {
            [self setRightBarButtonItems:@[negativeSeperator, _rightBarButtonItem]];
        }
        else
        {
            [self setRightBarButtonItems:@[negativeSeperator]];
        }
        [negativeSeperator release];
    }
    else
    {
        [self setRightBarButtonItem:_rightBarButtonItem animated:NO];
    }
}

#endif
@end
bubuko.com,布布扣
bubuko.com,布布扣

 

项目源码不做任何修改,问题解决;

添加Button:

bubuko.com,布布扣
UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
self.navigationItem.leftBarButtonItem = leftBarItem;
[leftBarItem release];
bubuko.com,布布扣

 

iOS7 UI兼容 导航栏按钮边距,布布扣,bubuko.com

iOS7 UI兼容 导航栏按钮边距

标签:style   blog   class   code   c   java   

原文地址:http://www.cnblogs.com/swu-luo/p/3734377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
分享档案
周排行
mamicode.com排行更多图片
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!