重写- (CGSize)sizeThatFits:(CGSize)size方法:
#import "CustomNavigationbar.h"
@implementation CustomNavigationbar
-(instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.barTintColor = [UIColor blueColor];
}
return self;
}
-(CGSize)sizeThatFits:(CGSize)size {
CGSize navigationSize = [super sizeThatFits:size];
navigationSize = CGSizeMake(navigationSize.width, navigationSize.height + 20);
return navigationSize;
}
使用:
TableViewController *controller = [[TableViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc]
initWithNavigationBarClass:[CustomNavigationbar class] toolbarClass:nil ];
nav.viewControllers = @[controller];
[self presentViewController:nav animated:YES completion:nil];
THE END
近期评论