| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- //
- // KeyboardVipTipView.swift
- // AiKeyboard
- //
- // Created by Destiny on 2025/4/25.
- //
- import UIKit
- import Lottie
- class KeyboardVipTipView: UIView {
-
- var unlockBtnClosure: (() -> ())?
-
- var backBtnClosure: (() -> ())?
-
- lazy var bgImageView: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "keyboard_bg")
- return imageView
- }()
-
- lazy var backBtn: UIButton = {
-
- let btn = UIButton()
- btn.setImage(UIImage(named: "keyboard_back_btn"), for: .normal)
- btn.layer.shadowOffset = CGSize(width: 0, height: 0)
- btn.layer.shadowColor = UIColor.hexStringColor(hexString: "#000000", alpha: 0.12).cgColor
- btn.layer.shadowRadius = 6.1
- btn.addTarget(self, action: #selector(backButtonClickAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var topImageView: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "keyboard_vip_top")
- return imageView
- }()
-
- lazy var mainView: UIView = {
-
- let view = UIView()
- view.backgroundColor = .white
- view.layer.cornerRadius = 20
- return view
- }()
-
- lazy var mainLabel: UILabel = {
-
- let label = UILabel()
- label.numberOfLines = 2
- label.text = "您的免费提问次数已用完\n可订阅会员解锁无线提问"
- label.font = .systemFont(ofSize: 16, weight: .medium)
- label.textColor = .hexStringColor(hexString: "#000000", alpha: 0.8)
- label.setLineSpacing(5)
- return label
- }()
-
- lazy var unlockBtnAnimation: LottieAnimationView = {
-
- let animate = LottieAnimationView(name: "vip_button")
- animate.loopMode = .loop
- animate.backgroundColor = .clear
-
- animate.isUserInteractionEnabled = true
- let tap = UITapGestureRecognizer(target: self, action: #selector(unlockBtnAction))
- animate.addGestureRecognizer(tap)
- return animate
- }()
-
- lazy var unlockTextImageView: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "keyboard_vip_unlock_text")
- return imageView
- }()
-
- lazy var unlockLabel: UILabel = {
-
- // 注册自定义字体
- if let fontURL = Bundle.main.url(forResource: "tbmct", withExtension: "ttf") {
- CTFontManagerRegisterFontsForURL(fontURL as CFURL, .process, nil)
- }
-
- // let name = self.getFontPostScriptName(from: "淘宝买菜体.ttf")
- let label = UILabel()
- label.text = "¥0.1/天解锁"
- label.font = UIFont(name: "TBMCYXT", size: 24)
- label.textColor = .white
- return label
- }()
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- setUI()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func getFontPostScriptName(from fontFile: String) -> String? {
- guard let path = Bundle.main.path(forResource: fontFile, ofType: nil) else {
- return nil
- }
- let fontURL = URL(fileURLWithPath: path)
- guard let fontDataProvider = CGDataProvider(url: fontURL as CFURL),
- let font = CGFont(fontDataProvider) else {
- return nil
- }
- return font.postScriptName as String?
- }
- }
- extension KeyboardVipTipView {
-
- @objc func backButtonClickAction() {
-
- self.backBtnClosure?()
- }
-
- @objc func unlockBtnAction() {
-
- self.unlockBtnClosure?()
- }
- }
- extension KeyboardVipTipView {
-
- func setUI() {
-
- self.addSubview(bgImageView)
- bgImageView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
-
- self.addSubview(backBtn)
- backBtn.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 32, height: 32))
- make.left.equalTo(12)
- make.top.equalTo(14)
- }
-
- self.addSubview(topImageView)
- topImageView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 264, height: 98.5))
- make.top.equalTo(47)
- make.centerX.equalToSuperview()
- }
-
- self.addSubview(mainView)
- mainView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 285, height: 122))
- make.centerX.equalToSuperview()
- make.top.equalTo(topImageView.snp.bottom).offset(-9)
- }
-
- mainView.addSubview(mainLabel)
- mainLabel.snp.makeConstraints { make in
- make.centerX.equalToSuperview()
- make.top.equalTo(21)
- }
-
- self.addSubview(unlockBtnAnimation)
- unlockBtnAnimation.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 300, height: 48))
- make.centerX.equalToSuperview()
- make.top.equalTo(mainView.snp.bottom).offset(-30)
- }
- unlockBtnAnimation.play()
-
- unlockBtnAnimation.addSubview(unlockTextImageView)
- unlockTextImageView.snp.makeConstraints { make in
- make.center.equalToSuperview()
- }
- }
- }
|