自定义UINavigationBar方法一子类化:
#import <UIKit/UIKit.h>
@interface CustomNavigationBar : UINavigationBar {
}
- (void)redrawNavigationBar;
@end
#import "CustomNavigationBar.h"
@implementation CustomNavigationBar
- (void)dealloc {
}
- (void)drawRect:(CGRect)rect {
// Drawing code.
UIImage *image = [UIImage imageNamed:@"title_bg.jpg"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
自定义UINavigationBar方法二类别方法:
#import <UIKit/UIKit.h>
@interface UINavigationBar(CustomBackground)
@end
#import "UINavigationBar+CustomBackground.h"
@implementation UINavigationBar(CustomBackground)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"title_bg.jpg"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
在你的ViewDidLoad 或者任何一个程序可以执行到的地方 写下如下代码,当然,你的searchBar得创建之后才行
[[_searchBar.subviews objectAtIndex:0] setHidden:YES];
这个代码 配合 上面的那个类别
- (void)drawRect:(CGRect)rect
}
@end