#import#define TOPVIEWTAG 0x10000 // 导航栏的图片@interface UIViewController (Chnbs)-(void)setupTopNavigationView;-(void)resizeNavigationView;-(CGRect)CGRectMake;-(void)showMessage:(NSString*)message;@en======================@implementation UIViewController (Chnbs)-(void)setupTopNavigationView{ self.navigationController.navigationBarHidden = YES; UIView *tpNavView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)]; tpNavView.tag = TOPVIEWTAG; [self.view addSubview:tpNavView]; [tpNavView release]; UIImageView *navImageView = [UIImageView ImageViewImageName:@"top_navigation_image.png" frame:tpNavView.bounds]; navImageView.tag = 10010; [tpNavView addSubview:navImageView]; UILabel *label = [UILabel LabWithFrame:tpNavView.bounds text:self.title textColor:[UIColor whiteColor] textAlign:NSTextAlignmentCenter font:[UIFont boldSystemFontOfSize:22]]; [tpNavView addSubview:label]; label.tag=10020; UIButton *back = [UIButton ButtonWithImageName:@"btn_back_image.png" hImageName:@"btn_back_image.png" frame:CGRectMake(5, 6, 45, 32) title:nil titleColor:nil font:nil target:self action:@selector(backButtonAction:)]; back.tag = 0x404; [tpNavView addSubview:back]; //FIX 添加导航的屏幕自动适配 tpNavView.autoresizingMask=UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth; navImageView.autoresizingMask=UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth; label.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;}-(void)resizeNavigationView{ UIView *topView = ASDynamicCast(UIView, [self.view viewWithTag:TOPVIEWTAG]); topView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 44); UIImageView *image = ASDynamicCast(UIImageView, [topView viewWithTag:10010]); image.frame = topView.bounds; UILabel *tLab = ASDynamicCast(UILabel, [topView viewWithTag:10020]); tLab.frame = topView.bounds; UIButton *back = ASDynamicCast(UIButton, [topView viewWithTag:0x404]); back.frame = CGRectMake(5, 6, 45, 32);}-(void)backButtonAction:(id)sender{ [self.navigationController popViewControllerAnimated:YES];}-(CGRect)CGRectMake{ CGRect topViewRec,bottonViewRec; CGRectDivide(self.view.bounds, &topViewRec, &bottonViewRec, 44, CGRectMinYEdge); return bottonViewRec;}-(void)showMessage:(NSString*)message{ if ([message length] > 0) { UIAlertView *av = [[UIAlertView alloc] initWithTitle:nil message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [av show]; [av release]; }}@end