123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // TSTGPTextView.swift
- // AIRingtone
- //
- // Created by 100Years on 2025/3/4.
- //
- class TSPromptTextView : TSBaseView{
-
- var randomTextArray:[String]
- var textChangedBlock:((String)->Void)
-
- init(randomTextArray: [String], textChangedBlock: @escaping (String) -> Void) {
- self.randomTextArray = randomTextArray
- self.textChangedBlock = textChangedBlock
- super.init(frame: .zero)
- }
-
- @MainActor required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- lazy var titleView: TSTGPTitleView = {
- let titleView = TSTGPTitleView()
- titleView.titleLab.text = "Enter a prompt".localized
- return titleView
- }()
-
- lazy var randomTextPicker: TSRandomTextPicker = {
- let textPicker = TSRandomTextPicker(texts: randomTextArray)
- return textPicker
- }()
-
- lazy var textBgView: UIView = {
- let textBgView = UIView()
-
- let bgImageView = UIImageView.createImageView(imageName: "textView_bg",contentMode: .scaleToFill)
- textBgView.addSubview(bgImageView)
- bgImageView.snp.makeConstraints { make in
- make.top.equalTo(0)
- make.centerX.equalToSuperview()
- make.width.equalTo(343*kDesignScale)
- make.height.equalTo(160*kDesignScale)
- }
- return textBgView
- }()
-
- lazy var customTextView: TSPlaceholderTextView = {
- let customTextView = TSPlaceholderTextView(
- placeholder: "Type your idea here.",
- text: "",
- font: .font(size: 16),
- textColor: .white,
- backgroundColor: .clear
- )
- customTextView.delegate = self
- return customTextView
- }()
-
-
- lazy var inspirationBtn: UIButton = {
- let inspirationBtn = UIButton.createButton(
- title: "Hint Inspiration".localized,
- image: UIImage(named: "textView_hint"),
- font: .font(size: 14),
- titleColor: .themeColor
- )
- { [weak self] in
- guard let self = self else { return }
- customTextView.text = randomTextPicker.getRandomText()
- textViewDidChange(customTextView)
- }
- inspirationBtn.contentEdgeInsets = UIEdgeInsets(top: 4, left: 40, bottom: 4, right: 50)
- inspirationBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -10, bottom: 0, right: 0)
- return inspirationBtn
- }()
-
-
- lazy var clearBtn: TSUIExpandedTouchButton = {
- let clearBtn = TSUIExpandedTouchButton()
- clearBtn.setUpButton(image: UIImage(named: "clear_text"))
- { [weak self] in
- guard let self = self else { return }
- customTextView.text = ""
- textViewDidChange(customTextView)
- }
- clearBtn.setImage(UIImage(named: "clear_gary_text"), for: .disabled)
- clearBtn.isEnabled = false
- return clearBtn
- }()
-
- let maxNum:Int = 1000
- var currenMun:Int = 0 {
- didSet{
- currenMunLab.text = "\(currenMun)"
- }
- }
- lazy var currenMunLab: UILabel = {
- let numLab = UILabel.createLabel(text: "\(currenMun)",font: .font(name: .PingFangSC,size: 12),textColor: .white)
- return numLab
- }()
-
- lazy var numView: UIView = {
- let numView = UIView()
-
- numView.addSubview(currenMunLab)
-
- let numLab = UILabel.createLabel(text: "/\(maxNum)",font: .font(name: .PingFangSC,size: 12),textColor: .white.withAlphaComponent(0.4))
- numView.addSubview(numLab)
-
- let lineView = UIView()
- lineView.cornerRadius = 0.5
- lineView.backgroundColor = .white
- numView.addSubview(lineView)
-
- currenMunLab.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.leading.equalTo(0)
- }
-
- numLab.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.leading.equalTo(currenMunLab.snp.trailing)
- }
-
- lineView.snp.makeConstraints { make in
- make.top.trailing.bottom.equalToSuperview()
- make.leading.equalTo(numLab.snp.trailing).offset(8)
- make.width.equalTo(1)
- make.height.equalTo(12)
- }
-
- return numView
- }()
-
- override func creatUI() {
- let titleViewH = titleView.viewH
-
- addSubview(titleView)
- titleView.snp.makeConstraints { make in
- make.top.equalTo(0)
- make.leading.trailing.equalTo(0)
- make.height.equalTo(titleViewH)
- }
-
- contentView.snp.updateConstraints { make in
- make.top.equalTo(titleViewH)
- }
-
- contentView.addSubview(textBgView)
- textBgView.snp.makeConstraints { make in
- make.top.equalTo(0)
- make.leading.equalTo(16)
- make.trailing.equalTo(-16)
- make.height.equalTo(160.0*kDesignScale)
- make.bottom.equalTo(-10)
- }
-
- textBgView.addSubview(customTextView)
- customTextView.snp.makeConstraints { make in
- make.top.equalTo(16)
- make.leading.equalTo(16)
- make.trailing.equalTo(-16)
- make.bottom.equalTo(-48)
- }
-
- textBgView.addSubview(inspirationBtn)
- inspirationBtn.snp.makeConstraints { make in
- make.height.equalTo(32)
- make.bottom.equalTo(0)
- make.leading.equalTo(0)
- }
-
- textBgView.addSubview(clearBtn)
- clearBtn.snp.makeConstraints { make in
- make.width.height.equalTo(14)
- make.bottom.equalTo(-14)
- make.trailing.equalTo(-14)
- }
-
- textBgView.addSubview(numView)
- numView.snp.makeConstraints { make in
- make.centerY.equalTo(clearBtn)
- make.trailing.equalTo(clearBtn.snp.leading).offset(-8)
- }
-
- }
- func getVipText()->String{
- return "Generate"
- // if kPurchaseDefault.isVip {
- // return "Generate"
- // }
- // return "Generate (\(kPurchaseDefault.freeNum(type: .generatePic)))"
- }
-
- }
- extension TSPromptTextView: UITextViewDelegate{
-
- func textViewDidBeginEditing(_ textView: UITextView) {
- // self.colComponent?.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .centeredVertically, animated: true)
- }
-
- func textViewDidChange(_ textView: UITextView) {
- currenMun = textView.text.count
- clearBtn.isEnabled = currenMun > 0
- textChangedBlock(textView.text)
- }
-
- }
|