@implementation ViewControllerFactory
#pragma mark ====== 适配iphone5公用的方法 ======
+(id)createViewControllerByControllerName:(NSString*) controllerName {
if (controllerName == nil || [controllerName isEqualToString:@""]) {
return nil;
}
NSString *controllerXibName = nil;
if (isIPhone5) {
controllerXibName = [NSString stringWithFormat:@"%@_iphone5",controllerName];
}else {
controllerXibName = controllerName;
}
Class class = NSClassFromString(controllerName);
return [[[class alloc] initWithNibName:controllerXibName bundle:nil] autorelease];
}
#pragma mark ====== 导航栏公用的方法 ======
+(void)initNavigationbar:(UIViewController *)tempViewController centerName:(NSString *)centerName rightButtonName:(NSString *)rightButtonName leftImage:(NSString *)leftImage rightImage:(NSString *)rightImage{
//自定义返回按钮。
UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
[tempButton setBackgroundImage:[UIImage imageNamed:leftImage] forState:UIControlStateNormal];
tempButton.frame=CGRectMake(0, 0, 50, 30);
[tempButton addTarget:tempViewController action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithCustomView:tempButton];
tempViewController.navigationItem.leftBarButtonItem=leftButton;
[leftButton release];
//解除绑定按钮。
UIButton *tempButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[tempButton1 setTitle:rightButtonName forState:UIControlStateNormal];
[tempButton1 setBackgroundImage:[UIImage imageNamed:rightImage] forState:UIControlStateNormal];
tempButton1.frame=CGRectMake(0, 0, 80, 30);
[tempButton1 addTarget:tempViewController action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]initWithCustomView:tempButton1];
tempViewController.navigationItem.rightBarButtonItem=rightButton;
[rightButton release];
//显示导航栏。
[UIView animateWithDuration:0.4 animations:^{
tempViewController.navigationController.navigationBarHidden = NO;
tempViewController.navigationController.navigationBar.tintColor = [UIColor blackColor];
tempViewController.navigationItem.title=centerName;
}];
}
一个小的封装test用的---判断iphone5 和导航栏封装。
猜你喜欢
转载自zhangmingwei.iteye.com/blog/1824996
今日推荐
周排行