iOS7 UI兼容 导航栏按钮边距_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > iOS7 UI兼容 导航栏按钮边距

iOS7 UI兼容 导航栏按钮边距

 2014/5/18 13:24:30  swu_luo  博客园  我要评论(0)
  • 摘要:转载自:http://www.cnblogs.com/maxfong/p/3375167.htmliOS7之前的UI为:而在iOS7中,由于设计方面的原因,使得UI变为:修改的方法重写UINavigationItem的setLeftBarButtonItem和setRightBarButtonItem方法,使之与之前版本兼容;代码如下:@interfaceUINavigationItem(margin)@end@implementationUINavigationItem(margin
  • 标签:iOS 兼容

class="postTitle">转载自:http://www.cnblogs.com/maxfong/p/3375167.html

iOS7之前的UI为:

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

 

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

代码如下:

@interface UINavigationItem (margin)

@end
复制代码
@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
复制代码

 

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

添加Button:

UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
self.navigationItem.leftBarButtonItem = leftBarItem;
[leftBarItem release];

 

发表评论
用户名: 匿名