├── .gitignore ├── LICENSE ├── README.md ├── UINavigationItem+iOS7Spacing.h ├── UINavigationItem+iOS7Spacing.m ├── UINavigationItem-iOS7Spacing.podspec ├── ios6-default.png ├── ios7-default.png └── ios7-fixed.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | */build/* 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | 20 | #CocoaPods 21 | Pods 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Marius Kažemėkaitis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UINavigationItem-iOS7Spacing 2 | ============================ 3 | 4 | Category to fix iOS 7 UINavigationItem spacing. 5 | 6 | leftBarButtonItem position on iOS 5/6 7 | 8 | ![iOS 6 default](ios6-default.png) 9 | 10 | 11 | leftBarButtonItem position on iOS 7 12 | 13 | ![iOS 7 default](ios7-default.png) 14 | 15 | 16 | Fixed leftBarButtonItem position on iOS 7 17 | 18 | ![iOS 7 fixed](ios7-fixed.png) 19 | 20 | You do not have to do anything else, except include this category in your *-Prefix.pch file: 21 | 22 | ``` 23 | #ifdef __OBJC__ 24 | #import 25 | #import 26 | #import "UINavigationItem+iOS7Spacing.h" 27 | #endif 28 | ``` 29 | 30 | Fully tested on iOS 6/7. -------------------------------------------------------------------------------- /UINavigationItem+iOS7Spacing.h: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationItem+iOS7Spacing.h 3 | // 4 | // Created by Marius Kažemėkaitis on 2013-10-11. 5 | // Copyright (c) 2013 Lemon Labs. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UINavigationItem (iOS7Spacing) 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /UINavigationItem+iOS7Spacing.m: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationItem+iOS7Spacing.m 3 | // 4 | // Created by Marius Kažemėkaitis on 2013-10-11. 5 | // Copyright (c) 2013 Lemon Labs. All rights reserved. 6 | // 7 | 8 | #import "UINavigationItem+iOS7Spacing.h" 9 | #import 10 | 11 | @implementation UINavigationItem (iOS7Spacing) 12 | 13 | - (BOOL)isIOS7 14 | { 15 | return ([[[UIDevice currentDevice] systemVersion] compare:@"7" options:NSNumericSearch] != NSOrderedAscending); 16 | } 17 | 18 | - (UIBarButtonItem *)spacer 19 | { 20 | UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 21 | space.width = -11; 22 | return space; 23 | } 24 | 25 | - (void)mk_setLeftBarButtonItem:(UIBarButtonItem *)leftBarButtonItem 26 | { 27 | if ([self isIOS7] && leftBarButtonItem) { 28 | [self mk_setLeftBarButtonItem:nil]; 29 | [self mk_setLeftBarButtonItems:@[[self spacer], leftBarButtonItem]]; 30 | } else { 31 | if ([self isIOS7]) { 32 | [self mk_setLeftBarButtonItems:nil]; 33 | } 34 | [self mk_setLeftBarButtonItem:leftBarButtonItem]; 35 | } 36 | } 37 | 38 | - (void)mk_setLeftBarButtonItems:(NSArray *)leftBarButtonItems 39 | { 40 | if ([self isIOS7] && leftBarButtonItems && leftBarButtonItems.count > 0) { 41 | 42 | NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:leftBarButtonItems.count + 1]; 43 | [items addObject:[self spacer]]; 44 | [items addObjectsFromArray:leftBarButtonItems]; 45 | 46 | [self mk_setLeftBarButtonItems:items]; 47 | } else { 48 | [self mk_setLeftBarButtonItems:leftBarButtonItems]; 49 | } 50 | } 51 | 52 | - (void)mk_setRightBarButtonItem:(UIBarButtonItem *)rightBarButtonItem 53 | { 54 | if ([self isIOS7] && rightBarButtonItem) { 55 | [self mk_setRightBarButtonItem:nil]; 56 | 57 | // Fix position issue in system vc, eg. cancel button in UIImagePickerController 58 | if (rightBarButtonItem.customView) { 59 | [self mk_setRightBarButtonItems:@[[self spacer], rightBarButtonItem]]; 60 | } else { 61 | [self mk_setRightBarButtonItem:rightBarButtonItem]; 62 | } 63 | } else { 64 | if ([self isIOS7]) { 65 | [self mk_setRightBarButtonItems:nil]; 66 | } 67 | [self mk_setRightBarButtonItem:rightBarButtonItem]; 68 | } 69 | } 70 | 71 | - (void)mk_setRightBarButtonItems:(NSArray *)rightBarButtonItems 72 | { 73 | if ([self isIOS7] && rightBarButtonItems && rightBarButtonItems.count > 0) { 74 | 75 | NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:rightBarButtonItems.count + 1]; 76 | [items addObject:[self spacer]]; 77 | [items addObjectsFromArray:rightBarButtonItems]; 78 | 79 | [self mk_setRightBarButtonItems:items]; 80 | } else { 81 | [self mk_setRightBarButtonItems:rightBarButtonItems]; 82 | } 83 | } 84 | 85 | + (void)mk_swizzle:(SEL)aSelector 86 | { 87 | SEL bSelector = NSSelectorFromString([NSString stringWithFormat:@"mk_%@", NSStringFromSelector(aSelector)]); 88 | 89 | Method m1 = class_getInstanceMethod(self, aSelector); 90 | Method m2 = class_getInstanceMethod(self, bSelector); 91 | 92 | method_exchangeImplementations(m1, m2); 93 | } 94 | 95 | + (void)load 96 | { 97 | [self mk_swizzle:@selector(setLeftBarButtonItem:)]; 98 | [self mk_swizzle:@selector(setLeftBarButtonItems:)]; 99 | [self mk_swizzle:@selector(setRightBarButtonItem:)]; 100 | [self mk_swizzle:@selector(setRightBarButtonItems:)]; 101 | } 102 | 103 | @end -------------------------------------------------------------------------------- /UINavigationItem-iOS7Spacing.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "UINavigationItem-iOS7Spacing" 4 | s.version = "0.2" 5 | s.summary = "Category to fix iOS 7 UINavigationItem spacing." 6 | s.homepage = "https://github.com/lemonlabs/UINavigationItem-iOS7Spacing" 7 | s.screenshots = "https://raw2.github.com/lemonlabs/UINavigationItem-iOS7Spacing/master/ios6-default.png", "https://raw2.github.com/lemonlabs/UINavigationItem-iOS7Spacing/master/ios7-default.png" 8 | 9 | s.license = { :type => 'MIT', :file => 'LICENSE' } 10 | s.author = { "Marius Kažemėkaitis" => "marius@lemonlabs.lt" } 11 | s.platform = :ios, '6.0' 12 | s.source = { :git => "https://github.com/lemonlabs/UINavigationItem-iOS7Spacing.git", :tag => s.version.to_s } 13 | s.source_files = 'UINavigationItem+iOS7Spacing.{m,h}' 14 | s.requires_arc = true 15 | 16 | end -------------------------------------------------------------------------------- /ios6-default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lemonlabs/UINavigationItem-iOS7Spacing/7cd2cf95cd4512414565fd5cd571a3757e865ac2/ios6-default.png -------------------------------------------------------------------------------- /ios7-default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lemonlabs/UINavigationItem-iOS7Spacing/7cd2cf95cd4512414565fd5cd571a3757e865ac2/ios7-default.png -------------------------------------------------------------------------------- /ios7-fixed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lemonlabs/UINavigationItem-iOS7Spacing/7cd2cf95cd4512414565fd5cd571a3757e865ac2/ios7-fixed.png --------------------------------------------------------------------------------