TCUserAgreementController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // TCUserAgreementController.m
  3. // TCLVBIMDemo
  4. //
  5. // Created by zhangxiang on 16/9/14.
  6. // Copyright © 2016年 tencent. All rights reserved.
  7. //
  8. #import "TCUserAgreementController.h"
  9. #import "UIView+Additions.h"
  10. #import "AppDelegate.h"
  11. //#import "TCLoginModel.h"
  12. @implementation TCUserAgreementController
  13. {
  14. WKWebView *_webView;
  15. }
  16. -(instancetype)init{
  17. self = [super init];
  18. if (self) {
  19. }
  20. return self;
  21. }
  22. -(void)viewWillAppear:(BOOL)animated{
  23. [super viewWillAppear:animated];
  24. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
  25. }
  26. -(void)viewWillDisappear:(BOOL)animated
  27. {
  28. [super viewWillAppear:animated];
  29. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
  30. }
  31. -(void)viewDidLoad{
  32. [super viewDidLoad];
  33. self.navigationItem.title = NSLocalizedString(@"TCUserAgreement.TitleUserProtocol", nil);
  34. CGFloat bottom = self.view.height;
  35. BOOL hasBottomInsets = NO;
  36. if (@available(iOS 11, *)) {
  37. CGFloat bottomInset = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
  38. bottom -= bottomInset;
  39. hasBottomInsets = bottomInset > 0;
  40. }
  41. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, bottom - 50)];
  42. [self.view addSubview:_webView];
  43. NSString *path = [[NSBundle mainBundle] bundlePath];
  44. NSURL *baseURL = [NSURL fileURLWithPath:path];
  45. NSString * htmlPath = [[NSBundle mainBundle] pathForResource:@"UserProtocol"
  46. ofType:@"html"];
  47. NSString * htmlCont = [NSString stringWithContentsOfFile:htmlPath
  48. encoding:NSUTF8StringEncoding
  49. error:nil];
  50. [_webView loadHTMLString:htmlCont baseURL:baseURL];
  51. UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, bottom - 50, self.view.width, 0.5)];
  52. lineView1.backgroundColor = [UIColor grayColor];
  53. [self.view addSubview:lineView1];
  54. UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(self.view.width/2,lineView1.bottom, 0.5, 49)];
  55. lineView2.backgroundColor = [UIColor grayColor];
  56. [self.view addSubview:lineView2];
  57. if (hasBottomInsets) {
  58. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, bottom, self.view.width, 0.5)];
  59. lineView.backgroundColor = [UIColor grayColor];
  60. [self.view addSubview:lineView];
  61. }
  62. //同意
  63. UIButton *unAgreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  64. unAgreeBtn.frame = CGRectMake(0,lineView1.bottom, self.view.width/2, 49);
  65. [unAgreeBtn setTitle:NSLocalizedString(@"TCUserAgreement.TitleDisagree", nil) forState:UIControlStateNormal];
  66. [unAgreeBtn setTitleColor:RGB(237, 100, 85) forState:UIControlStateNormal];
  67. [unAgreeBtn addTarget:self action:@selector(unAgreeClick) forControlEvents:UIControlEventTouchUpInside];
  68. [self.view addSubview:unAgreeBtn];
  69. //不同意
  70. UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  71. agreeBtn.frame = CGRectMake(self.view.width/2 + 1, lineView1.bottom, self.view.width/2, 49);
  72. [agreeBtn setTitle:NSLocalizedString(@"TCUserAgreement.TitleAgree", nil) forState:UIControlStateNormal];
  73. [agreeBtn setTitleColor:RGB(237, 100, 85) forState:UIControlStateNormal];
  74. [agreeBtn addTarget:self action:@selector(agreeClick) forControlEvents:UIControlEventTouchUpInside];
  75. [self.view addSubview:agreeBtn];
  76. }
  77. -(void)unAgreeClick{
  78. if(_agree) _agree(NO);
  79. // AppDelegate *app = [UIApplication sharedApplication].delegate;
  80. // [[TCLoginModel sharedInstance] logout:^{
  81. // [app enterLoginUI];
  82. // }];
  83. }
  84. -(void)agreeClick{
  85. if(_agree) _agree(YES);
  86. // [[NSUserDefaults standardUserDefaults] setObject:@YES forKey:hasAgreeUserAgreement];
  87. // [[AppDelegate sharedAppDelegate] enterMainUI];
  88. }
  89. @end