1. 这个也是stackoverflow 里的做法。
xcode => File->new ->File->Objective c-> 选择 Category base 类选: UINavigationBar name写 curBar
#import "UINavigationBar+curBar.h"
@implementation UINavigationBar (curBar)
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize = CGSizeMake(self.frame.size.width,44+100);
return newSize;
}
@end
增加到类里边就可以使用了。
2. 替换 UINavigationBar 类
UIImageView *imageView = [[UIImageView alloc] initWithFrame:customView.frame];
imageView.image = [UIImage imageNamed:@"caidanlan"];
[customView addSubview:imageView];
[self.navigationController.navigationBar addSubview:customView];