CNLiveLoginViewController.swift 9.17 KB
//
//  CNLiveLoginViewController.swift
//  metaCode
//
//  Created by open on 2023/6/5.
//

import Foundation
import UIKit
import SnapKit

class CNLiveLoginViewController : CNLiveBaseViewController, UITextViewDelegate {
    
    
    lazy var headerView : UIImageView = {
        let headerView = UIImageView()
        headerView.backgroundColor = .white
        headerView.contentMode = .scaleAspectFit
        headerView.image = UIImage(named: "Login_page_header_icon")
        return headerView
    }()
    
    var phoneText = UITextField()//手机号
    var veriText = UITextField()//验证码
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //添加主视图
        self.view.addSubview(self.headerView)
        self.headerView.snp.makeConstraints { make in
            make.centerX.equalTo(self.view)
            make.top.left.right.equalTo(self.view)
            make.height.equalTo(250.0)
        }
        
        self.setupPhoneView()
        self.setupVeriCodeView()
        self.setupLoginButtonView()
    }
    
    deinit {
        print("已经销毁了")
    }
    
    
    func setupPhoneView() {
        
        let phoneV = UIView.init()
        phoneV.backgroundColor = .white
        self.view.addSubview(phoneV)
        phoneV.snp.makeConstraints { make in
            make.left.right.equalTo(self.view)
            make.top.equalTo(self.headerView.snp.bottom).offset(10)
            make.height.equalTo(50)
        }
        
        let areaButton = UIButton(type: .custom)
        areaButton.backgroundColor = .white
        areaButton.setTitle("+86", for: .normal)
        areaButton.setTitle("+86", for: .highlighted)
        areaButton.titleLabel?.font = BoldFont_16_Fit
        areaButton.setTitleColor(HexColor("#333333"), for: .normal)
        areaButton.setTitleColor(HexColor("#333333"), for: .highlighted)
        areaButton.addTarget(self, action: #selector(changeCityNumberMothod), for: .touchUpInside)
        phoneV.addSubview(areaButton)
        areaButton.snp.makeConstraints { make in
            make.centerY.equalTo(phoneV)
            make.left.equalTo(phoneV.left).offset(40)
            make.width.lessThanOrEqualTo(45)
        }
        
        let v_line = UILabel.init()
        v_line.backgroundColor = HexColor("#EBEBEB")
        phoneV.addSubview(v_line)
        v_line.snp.makeConstraints { make in
            make.centerY.equalTo(phoneV)
            make.left.equalTo(areaButton.snp.right).offset(10)
            make.width.equalTo(1)
            make.height.equalTo(areaButton.snp.height).multipliedBy(0.35)
        }
        
        let h_line = UILabel.init()
        h_line.backgroundColor = HexColor("#EBEBEB")
        phoneV.addSubview(h_line)
        h_line.snp.makeConstraints { make in
            make.left.equalTo(phoneV.left).offset(40)
            make.right.equalTo(phoneV.right).offset(-40)
            make.height.equalTo(v_line.snp.width)
            make.bottom.equalTo(phoneV.snp.bottom).offset(-1)
        }
        
        self.phoneText = UITextField.init()
        self.phoneText.backgroundColor = .white
        self.phoneText.placeholder = "输入手机号"
        self.phoneText.font = BoldFont_16_Fit
        self.phoneText.keyboardType = .numberPad
        self.phoneText.clearButtonMode = .whileEditing
        phoneV.addSubview(self.phoneText)
        self.phoneText.snp.makeConstraints { make in
            make.centerY.equalTo(phoneV)
            make.left.equalTo(areaButton.snp.right).offset(21)
            make.height.equalTo(areaButton.snp.height)
            make.right.equalTo(phoneV.right).offset(-40)
        }
    }
    
    func setupVeriCodeView() {
        
        let verView = UIView.init()
        verView.backgroundColor = .white
        self.view.addSubview(verView)
        verView.snp.makeConstraints { make in
            make.left.right.equalTo(self.view)
            make.top.equalTo(self.headerView.snp.bottom).offset(70)
            make.height.equalTo(50)
        }
        
        let h_line = UILabel.init()
        h_line.backgroundColor = HexColor("#EBEBEB")
        verView.addSubview(h_line)
        h_line.snp.makeConstraints { make in
            make.left.equalTo(verView.left).offset(40)
            make.right.equalTo(verView.right).offset(-40)
            make.height.equalTo(1)
            make.bottom.equalTo(verView.snp.bottom).offset(-1)
        }
        
        let codeButton = UIButton(type: .custom)
        codeButton.backgroundColor = .white
        codeButton.setTitle("获取验证码", for: .normal)
        codeButton.setTitle("获取验证码", for: .highlighted)
        codeButton.titleLabel?.font = Font_16_Fit
        codeButton.setTitleColor(HexColor("#0066FE"), for: .normal)
        codeButton.setTitleColor(HexColor("#0066FE"), for: .highlighted)
        codeButton.addTarget(self, action: #selector(changeCityNumberMothod), for: .touchUpInside)
        verView.addSubview(codeButton)
        codeButton.snp.makeConstraints { make in
            make.centerY.equalTo(verView)
            make.right.equalTo(verView.snp.right).offset(-40)
            make.width.lessThanOrEqualTo(90)
        }
        
        self.veriText = UITextField.init()
        self.veriText.backgroundColor = .white
        self.veriText.placeholder = "输入验证码"
        self.veriText.font = BoldFont_16_Fit
        self.veriText.keyboardType = .numberPad
        self.veriText.clearButtonMode = .whileEditing
        verView.addSubview(self.veriText)
        self.veriText.snp.makeConstraints { make in
            make.centerY.equalTo(verView)
            make.right.equalTo(codeButton.snp.left).offset(-20)
            make.height.equalTo(codeButton.snp.height)
            make.left.equalTo(verView.snp.left).offset(40)
        }
        
        let tipLabel = UILabel.init()
        tipLabel.text = "未注册的手机号验证后自动为您创建元码账户"
        tipLabel.textColor = HexColor("#464646")
        tipLabel.textAlignment = .left
        tipLabel.font = Font_11_Fit
        self.view.addSubview(tipLabel)
        tipLabel.snp.makeConstraints { make in
            make.centerX.equalTo(self.view)
            make.left.right.equalTo(self.view).offset(40)
            make.top.equalTo(verView.snp.bottom).offset(10)
        }
    }
    
    func setupLoginButtonView() {
        
        let selectButton = UIButton(type: .custom)
        selectButton.backgroundColor = .white
        selectButton.setImage(UIImage(named: "Login_body_choose_btn_nomal"), for: .normal)
        selectButton.setImage(UIImage(named: "Login_body_choose_btn_nomal"), for: .highlighted)
        selectButton.setImage(UIImage(named: "Login_body_choose_btn_select"), for: .selected)
        selectButton.contentMode = .scaleAspectFill
        selectButton.addTarget(self, action: #selector(changeSelectBtnMothod), for: .touchUpInside)
        view.addSubview(selectButton)
        selectButton.snp.makeConstraints { make in
            make.bottom.equalTo(view.snp.bottom).offset(-50)
            make.left.equalTo(view.snp.left).offset(30)
            make.height.equalTo(15)
        }
    
        let attributedString = NSMutableAttributedString(string: "我已阅读并同意《APP用户服务协议》《个人信息保护政策》",
                                                         attributes: [.foregroundColor: HexColor("#999999") as Any, .font: Font_10])
        let p_Range = NSRange(attributedString.string.range(of: "《APP用户服务协议》")!, in: attributedString.string)
        attributedString.addAttribute(.link, value: "delegate://", range: p_Range)
        let i_Range = NSRange(attributedString.string.range(of: "《个人信息保护政策》")!, in: attributedString.string)
        attributedString.addAttribute(.link, value: "info://", range: i_Range)
        let textView: UITextView = UITextView.init()
        textView.backgroundColor = .white
        textView.isEditable = false
        textView.isScrollEnabled = false
        textView.delegate = self
        textView.attributedText = attributedString
        view.addSubview(textView)
        textView.snp.makeConstraints { make in
            make.centerY.equalTo(selectButton)
            make.left.equalTo(selectButton.snp.right)
            make.right.equalTo(view.snp.right).offset(-30)
        }
        
        let loginButton = UIButton(type: .custom)
//        loginButton.
        

    }
}

extension CNLiveLoginViewController {
    
    @objc func changeCityNumberMothod(sender : UIButton) {
        
    }
    
    @objc func sendVerifiCodeMothod(sender : UIButton) {
        
    }
    
    @objc func changeSelectBtnMothod(sender : UIButton) {
//        sender.isSelected =
    }
}

extension CNLiveLoginViewController {
    func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        return false
    }
    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        if URL.absoluteString == "delegate://" {
            print("《APP用户服务协议》")
            return false
        }else{
            print("《个人信息保护政策》")
            return false
        }
    }
}