UserAgreementViewController+UI.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // UserAgreementViewController+UI.swift
  3. // TXLiteAVDemo
  4. //
  5. // Created by lijie on 2020/6/23.
  6. // Copyright © 2020 Tencent. All rights reserved.
  7. //
  8. import Foundation
  9. import SnapKit
  10. import WebKit
  11. import TXAppBasic
  12. extension UserAgreementViewController {
  13. func setupUI() {
  14. self.title = LoginLocalize(key:"V2.Live.LinkMicNew.termsandconditions")
  15. let htmlPath = Bundle.main.path(forResource: "UserProtocol", ofType: "html")
  16. var htmlContent = ""
  17. do {
  18. htmlContent = try String(contentsOfFile: htmlPath ?? "")
  19. } catch {
  20. }
  21. let lineView1 = UIView()
  22. lineView1.backgroundColor = UIColor.gray
  23. view.addSubview(lineView1)
  24. lineView1.snp.remakeConstraints { (make) in
  25. make.width.equalTo(view)
  26. make.height.equalTo(0.5)
  27. make.leading.equalTo(0)
  28. make.bottom.equalTo(view).offset(-50 - bottomPadding)
  29. }
  30. let lineView2 = UIView()
  31. lineView2.backgroundColor = UIColor.gray
  32. view.addSubview(lineView2)
  33. lineView2.snp.remakeConstraints { (make) in
  34. make.width.equalTo(0.5)
  35. make.height.equalTo(49)
  36. make.leading.equalTo(view.snp.trailing).dividedBy(2)
  37. make.top.equalTo(lineView1.snp.bottom)
  38. }
  39. let agreeBtn = UIButton()
  40. agreeBtn.setTitle(LoginLocalize(key:"V2.Live.LinkMicNew.agree"), for: .normal)
  41. agreeBtn.setTitleColor(UIColor(0x0062E3), for: .normal)
  42. view.addSubview(agreeBtn)
  43. agreeBtn.snp.remakeConstraints { (make) in
  44. make.width.equalTo(view).dividedBy(2)
  45. make.height.equalTo(49)
  46. make.leading.equalTo(0)
  47. make.top.equalTo(lineView1.snp.bottom)
  48. }
  49. agreeBtn.addTarget(self, action: #selector(agreeBtnClick), for: .touchUpInside)
  50. let unAgreeBtn = UIButton()
  51. unAgreeBtn.setTitle(LoginLocalize(key:"V2.Live.LinkMicNew.disagree"), for: .normal)
  52. unAgreeBtn.setTitleColor(UIColor(0x0062E3), for: .normal)
  53. view.addSubview(unAgreeBtn)
  54. unAgreeBtn.snp.remakeConstraints { (make) in
  55. make.width.equalTo(view).dividedBy(2)
  56. make.height.equalTo(49)
  57. make.leading.equalTo(view.snp.trailing).dividedBy(2)
  58. make.top.equalTo(lineView1.snp.bottom)
  59. }
  60. unAgreeBtn.addTarget(self, action: #selector(unAgreeBtnClick), for: .touchUpInside)
  61. let webView = WKWebView()
  62. webView.loadHTMLString(htmlContent, baseURL: Bundle.main.bundleURL)
  63. view.addSubview(webView)
  64. webView.snp.remakeConstraints { (make) in
  65. make.top.equalTo(topPadding)
  66. make.bottom.equalTo(lineView1.snp.top)
  67. make.leading.equalTo(0)
  68. make.width.equalTo(view)
  69. }
  70. }
  71. @objc func agreeBtnClick() {
  72. agree()
  73. }
  74. @objc func unAgreeBtnClick() {
  75. unAgree()
  76. }
  77. func agree() {
  78. UserDefaults.standard.set(true, forKey: UserAgreementViewController.UserAgreeKey)
  79. UserDefaults.standard.synchronize()
  80. self.dismiss(animated: true, completion: completion)
  81. }
  82. func unAgree() {
  83. UserDefaults.standard.set(false, forKey: UserAgreementViewController.UserAgreeKey)
  84. UserDefaults.standard.synchronize()
  85. self.dismiss(animated: true, completion: completion)
  86. }
  87. }