DMBaseViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // DMBaseViewController.m
  3. // iphoneLive
  4. //
  5. // Created by DMY on 2017/4/2.
  6. // Copyright © 2017年 DMY. All rights reserved.
  7. //
  8. #import "DMBaseViewController.h"
  9. #import "TCBaseAppDelegate.h"
  10. #define CPLAY
  11. @interface DMBaseViewController ()
  12. @property(nonatomic, strong) UILabel *titleLab;
  13. @property(nonatomic, strong) UIButton *rightButton;
  14. @property(nonatomic, strong) UIView *navtion;
  15. @end
  16. @implementation DMBaseViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. NSLog(@"base controller");
  20. self.view.backgroundColor = [UIColor whiteColor];
  21. [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor whiteColor];
  22. if (@available(iOS 11.0, *)) {
  23. } else {
  24. // Fallback on earlier versions
  25. }
  26. if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
  27. // self.edgesForExtendedLayout = UIRectEdgeAll;
  28. self.edgesForExtendedLayout = UIRectEdgeNone;
  29. }
  30. // Do any additional setup after loading the view.
  31. }
  32. -(void)viewWillLayoutSubviews
  33. {
  34. [super viewWillLayoutSubviews];
  35. // self.view.frame = CGRectMake(self.view.frame.origin.x,20, self.view.frame.size.width, self.view.frame.size.height);
  36. }
  37. -(void)viewDidLayoutSubviews
  38. {
  39. [super viewDidLayoutSubviews];
  40. // self.view.frame = CGRectMake(self.view.frame.origin.x,20, self.view.frame.size.width, self.view.frame.size.height);
  41. }
  42. -(void)navtionWithTitle:(NSString *)title{
  43. self.navtion = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kStatusBarHeight + kNavigationBarHeight)];
  44. self.navtion.backgroundColor = navigationBGColor;
  45. self.titleLab = [[UILabel alloc]init];
  46. self.titleLab.text = title;
  47. [self.titleLab setFont:navtionTitleFont];
  48. self.titleLab.textColor = navtionTitleColor;
  49. self.titleLab.frame = CGRectMake(0, kStatusBarHeight,kScreenW,kNavigationBarHeight);
  50. self.titleLab.textAlignment = NSTextAlignmentCenter;
  51. [self.navtion addSubview:self.titleLab];
  52. UIButton *returnBtn = [[UIButton alloc]init];
  53. returnBtn.frame = CGRectMake(10,kStatusBarHeight,kNavigationBarHeight,kNavigationBarHeight);
  54. [returnBtn.imageView setContentMode:UIViewContentModeScaleAspectFill];
  55. // returnBtn.tintColor = [UIColor blackColor];
  56. [returnBtn setImage:[UIImage imageNamed:@"uplive_left_back_icon"] forState:UIControlStateNormal];
  57. [returnBtn addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  58. [self.navtion addSubview:returnBtn];
  59. //隐藏分割线
  60. // UIView *fg =[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_navtion.frame)-.5, kScreenW, .5)];
  61. // fg.backgroundColor =UIColorFromRGB(0xe5e5e5);
  62. // [_navtion addSubview:fg];
  63. [self.view addSubview:self.navtion];
  64. }
  65. -(void)setLeftButtonWith:(NSString *)title
  66. {
  67. UIButton *leftbutton = [UIButton buttonWithType:UIButtonTypeSystem];
  68. [leftbutton setTitle:title forState:UIControlStateNormal];
  69. leftbutton.tintColor = [UIColor whiteColor];
  70. UIButton *bigBTN = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW - 100, 0, kScreenW/2 - 50, 64)];
  71. [bigBTN addTarget:self action:@selector(doLeftClick) forControlEvents:UIControlEventTouchUpInside];
  72. [bigBTN setBackgroundColor:[UIColor clearColor]];
  73. [self.navtion addSubview:bigBTN];
  74. leftbutton.frame = CGRectMake(kScreenW - 60,30,60,20);
  75. // [leftbutton.imageView setContentMode:UIViewContentModeScaleAspectFit];
  76. leftbutton.tintColor = [UIColor blackColor];
  77. // [leftbutton setImage:[UIImage imageNamed:@"icon_arrow_leftsssa.png"] forState:UIControlStateNormal];
  78. [leftbutton addTarget:self action:@selector(doLeftClick) forControlEvents:UIControlEventTouchUpInside];
  79. [self.navtion addSubview:leftbutton];
  80. }
  81. - (void)doLeftClick {
  82. if([self.navdelegate respondsToSelector:@selector(navLeftButtonClick)])
  83. {
  84. [self.navdelegate navLeftButtonClick];
  85. }
  86. }
  87. -(void)doReturn{
  88. [self.navigationController popViewControllerAnimated:YES];
  89. [self dismissViewControllerAnimated: YES completion:nil];
  90. }
  91. - (void)didReceiveMemoryWarning {
  92. [super didReceiveMemoryWarning];
  93. // Dispose of any resources that can be recreated.
  94. }
  95. -(BOOL)shouldAutorotate
  96. {
  97. return NO;
  98. }
  99. #pragma mark - Navigation
  100. // In a storyboard-based application, you will often want to do a little preparation before navigation
  101. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  102. // Get the new view controller using [segue destinationViewController].
  103. // Pass the selected object to the new view controller.
  104. }
  105. @end