//Overide the drawing of the background UINavigationBar
@implementation UINavigationBar (CustomImage)
- (Class)class
{
returnNSClassFromString(@"HFNavigationBar");
}
- (void)drawRect:(CGRect)rect
{
UIImage *image = [UIImageimageNamed:@"navigation@2x.png"];
[image drawInRect:CGRectMake(self.bounds.origin.x,self.bounds.origin.y,self.bounds.size.width,self.bounds.size.height+5) ];
self.tintColor = [UIColorclearColor];
}
//让title居中 否则会根据lefttile 和righttitle的存在与否进行变化
-(void)layoutSubviews {
[superlayoutSubviews];
for (id viewinself.subviews) {
if ([viewisKindOfClass:NSClassFromString(@"UILabel")]) {
// Do whatever you want with view here
[viewsetFrame:CGRectMake(0 ,0,320,44) ];
}
}
}
@end
titleLabel.backgroundColor = [UIColorclearColor];
titleLabel.font = [UIFontboldSystemFontOfSize:22.0];
titleLabel.shadowColor = [UIColorcolorWithWhite:0.0alpha:0.5];
titleLabel.textAlignment =UITextAlignmentCenter;
titleLabel.textColor = [UIColorwhiteColor];// change this color
[titleLabelsetAutoresizingMask:UIViewAutoresizingNone ];
self.navigationItem.titleView =titleLabel;