Skip to content

Instantly share code, notes, and snippets.

@jasondinh
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasondinh/104555677b8b3020365f to your computer and use it in GitHub Desktop.
Save jasondinh/104555677b8b3020365f to your computer and use it in GitHub Desktop.
//.h file
#import <UIKit/UIKit.h>
@interface UINavigationBar (customNav)
@property (nonatomic) NSValue *customSize;
@end
//.m file
#import <objc/runtime.h>
NSString * const kCustomSizeKey = @"kCustomSizeKey";
@implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize;
if (self.customSize) {
newSize = [self.customSize CGSizeValue];
return newSize;
}
else {
return size;
}
}
- (void)setCustomSize:(NSValue *)customSize {
objc_setAssociatedObject(self, (__bridge const void *)kCustomSizeKey, customSize, OBJC_ASSOCIATION_COPY);
}
- (NSValue *)customSize
{
return objc_getAssociatedObject(self, (__bridge const void *)kCustomSizeKey);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment