MJTempViewController.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // MJTempViewController.m
  3. // MJRefreshExample
  4. //
  5. // Created by MJ Lee on 15/9/22.
  6. // Copyright © 2015年 小码哥. All rights reserved.
  7. //
  8. #import "MJTempViewController.h"
  9. @interface MJTempViewController ()
  10. @end
  11. @implementation MJTempViewController
  12. #pragma mark - 单例
  13. static id instance_;
  14. + (instancetype)sharedInstance
  15. {
  16. static dispatch_once_t onceToken;
  17. dispatch_once(&onceToken, ^{
  18. instance_ = [[self alloc] init];
  19. });
  20. return instance_;
  21. }
  22. + (instancetype)allocWithZone:(struct _NSZone *)zone
  23. {
  24. static dispatch_once_t onceToken;
  25. dispatch_once(&onceToken, ^{
  26. instance_ = [super allocWithZone:zone];
  27. });
  28. return instance_;
  29. }
  30. #pragma mark - 初始化
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.statusBarStyle = UIStatusBarStyleLightContent;
  34. self.view.backgroundColor = [UIColor clearColor];
  35. UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[@"示例1", @"示例2", @"示例3"]];
  36. control.tintColor = [UIColor orangeColor];
  37. control.frame = self.view.bounds;
  38. control.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  39. control.selectedSegmentIndex = 0;
  40. [control addTarget:self action:@selector(contorlSelect:) forControlEvents:UIControlEventValueChanged];
  41. [self.view addSubview:control];
  42. }
  43. - (void)contorlSelect:(UISegmentedControl *)control
  44. {
  45. UIWindow *keyWindow = [UIApplication sharedApplication].windows.firstObject;
  46. keyWindow.rootViewController = [keyWindow.rootViewController.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%zd", control.selectedSegmentIndex]];
  47. if (control.selectedSegmentIndex == 0) {
  48. self.statusBarStyle = UIStatusBarStyleLightContent;
  49. self.statusBarHidden = NO;
  50. } else if (control.selectedSegmentIndex == 1) {
  51. self.statusBarHidden = YES;
  52. } else if (control.selectedSegmentIndex == 2) {
  53. self.statusBarStyle = UIStatusBarStyleDefault;
  54. self.statusBarHidden = NO;
  55. }
  56. }
  57. - (UIStatusBarStyle)preferredStatusBarStyle
  58. {
  59. return self.statusBarStyle;
  60. }
  61. - (BOOL)prefersStatusBarHidden
  62. {
  63. return self.statusBarHidden;
  64. }
  65. - (void)setStatusBarHidden:(BOOL)statusBarHidden
  66. {
  67. _statusBarHidden = statusBarHidden;
  68. [self setNeedsStatusBarAppearanceUpdate];
  69. }
  70. - (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle
  71. {
  72. _statusBarStyle = statusBarStyle;
  73. [self setNeedsStatusBarAppearanceUpdate];
  74. }
  75. @end