// // BaseVIewContorller.m // Ifish // // Created by imac on 15/9/28. // Copyright © 2015年 imac. All rights reserved. // #import "BaseViewController.h" #import "AppDelegate.h" #import "UINavigationBar+Background.h" @interface BaseViewController () @property(nonatomic,strong)UILabel *titleLabel; @end @implementation BaseViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self initNav]; [self addTitleView]; self.view.backgroundColor = TABLE_BACKGROUD_COLOR; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController.navigationBar resetBackgroundImage]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; } -(void)addTitleView { UILabel*labe=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, kSizeFrom750(400), 44)]; self.titleLabel = labe; labe.textAlignment=NSTextAlignmentCenter; labe.textColor=[UIColor whiteColor]; labe.font = [UIFont systemFontOfSize:19]; self.navigationItem.titleView=labe; } -(void)setTitleString:(NSString *)titleString { _titleString = titleString; _titleLabel.text = _titleString; } - (void)addTitleViewWithTitle:(NSString *)title{ UILabel*labe=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, kSizeFrom750(300), 44)]; labe.text=title; labe.textAlignment=NSTextAlignmentCenter; labe.textColor=[UIColor whiteColor]; labe.font = [UIFont systemFontOfSize:19]; self.navigationItem.titleView=labe; } -(void)initNav{ _bakbutton = [UIButton buttonWithType:UIButtonTypeCustom]; _bakbutton.frame = CGRectMake(0,0,48,44); [_bakbutton setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal]; _bakbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [_bakbutton addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside]; // [_bakbutton setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)]; _back=[[UIBarButtonItem alloc] initWithCustomView:_bakbutton]; UIBarButtonItem *fixedButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; fixedButtonItem.width = -kSizeFrom750(30); self.navigationItem.leftBarButtonItems = @[fixedButtonItem, _back]; _rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; _rightButton.frame = CGRectMake(0,0,48,44); _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; UIBarButtonItem *rightSpaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; rightSpaceItem.width = -kSizeFrom750(50); _rightItem=[[UIBarButtonItem alloc] initWithCustomView:_rightButton]; self.navigationItem.rightBarButtonItems = @[_rightItem, rightSpaceItem]; } -(void)goBackAction{ [self.navigationController popViewControllerAnimated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(void)showTitle:(NSString*)title messsage:(NSString*)message{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"cancel Action"); }]; [alertController addAction:cancelAction]; [self presentViewController:alertController animated:YES completion:nil]; } -(void)creatMyindicaterView{ // _indicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; // // _indicatorView.center=CGPointMake(kScreenSize.width/2, kScreenSize.height/2+100); // //[_indicatorView startAnimating]; // _indicatorView.frame=CGRectMake(kScreenSize.width/2-20,kScreenSize.height/2-20,40, 40); // // _indicatorView.backgroundColor=[UIColor lightGrayColor]; // [self.view addSubview:_indicatorView]; } #pragma mark - 竖屏时,显示状态栏 -(BOOL)prefersStatusBarHidden{ return NO; } //白色状态栏 - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } #pragma mark - 屏幕Autorotate -(BOOL)shouldAutorotate{ return YES; } #pragma mark 屏幕支持的旋转方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface { return (interface == UIInterfaceOrientationPortrait || interface == UIInterfaceOrientationLandscapeRight); } // #ifdef IOS6 - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; } #endif // #pragma mark 支持哪些方向 -(UIInterfaceOrientationMask)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeRight; } #pragma mark 一开始希望的屏幕方向 -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationPortrait; } #pragma mark - 屏幕旋转 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { } } @end