123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- //
- // TSPromptTextView.swift
- // AIEmoji
- //
- // Created by 100Years on 2025/3/11.
- //
- 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 robotImageView: UIImageView = {
- let robotImageView = UIImageView.createImageView(imageName: "aichat_avatar")
- return robotImageView
- }()
-
-
- lazy var randomTextPicker: TSRandomTextPicker = {
- let textPicker = TSRandomTextPicker(texts: kRandomTextArray)
- return textPicker
- }()
-
- lazy var textBgView: UIView = {
- let textBgView = UIView()
- textBgView.backgroundColor = "#333333".uiColor
- textBgView.cornerRadius = 12
- return textBgView
- }()
-
- lazy var customTextView: TSPlaceholderTextView = {
- let customTextView = TSPlaceholderTextView(
- placeholder: "Type your idea here.".localized,
- text: "",
- font: .font(size: 14),
- textColor: .white,
- backgroundColor: "#333333".uiColor
- )
- customTextView.delegate = self
- customTextView.returnKeyType = .send
- return customTextView
- }()
-
- lazy var inspirationBtn: UIButton = {
- let inspirationBtn = UIButton.createButton(
- title: "Hint Inspiration".localized,
- image: UIImage(named: "inspiration_yellow"),
- backgroundColor:"#FECB34".uiColor.withAlphaComponent(0.1),
- font: .font(size: 12),
- titleColor: .themeColor,
- corner: 8.0)
- { [weak self] in
- guard let self = self else { return }
- customTextView.text = randomTextPicker.getRandomText()
- textViewDidChange(customTextView)
- }
- inspirationBtn.contentEdgeInsets = UIEdgeInsets(top: 4, left: 7, bottom: 4, right: 7)
- inspirationBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -4, bottom: 0, right: 0)
- inspirationBtn.isHidden = false
- return inspirationBtn
- }()
-
- lazy var clearBtn: UIButton = {
- let clearBtn = UIButton.createButton(
- image: UIImage(named: "clear_text")
- )
- { [weak self] in
- guard let self = self else { return }
- customTextView.text = ""
- textViewDidChange(customTextView)
- }
- clearBtn.isHidden = true
- return clearBtn
- }()
-
- override func creatUI() {
-
- contentView.addSubview(robotImageView)
- robotImageView.snp.makeConstraints { make in
- make.top.equalTo(0)
- make.leading.equalTo(16)
- make.width.height.equalTo(82)
- }
-
- contentView.addSubview(textBgView)
- textBgView.snp.makeConstraints { make in
- make.top.equalTo(57)
- make.leading.equalTo(16)
- make.trailing.equalTo(-16)
- make.height.equalTo(182.0)
- // make.height.equalTo(182.0*kDesignScale)
- // make.bottom.equalTo(-20)
- make.bottom.equalTo(0)
- }
-
- textBgView.addSubview(customTextView)
- customTextView.snp.makeConstraints { make in
- make.top.equalTo(21)
- make.leading.equalTo(16)
- make.trailing.equalTo(-16)
- make.bottom.equalTo(-21)
- }
-
- textBgView.addSubview(inspirationBtn)
- inspirationBtn.snp.makeConstraints { make in
- make.height.equalTo(28)
- make.bottom.equalTo(-16)
- make.leading.equalTo(16)
- }
-
- textBgView.addSubview(clearBtn)
- clearBtn.snp.makeConstraints { make in
- make.width.height.equalTo(16)
- make.bottom.equalTo(-16)
- make.trailing.equalTo(-16)
- }
- }
- func getVipText()->String{
- return "Generate".localized
- // 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) {
- let text = textView.text.replacingOccurrences(of: " ", with: "")
- clearBtn.isHidden = text.count > 0 ? false : true
- textChangedBlock(textView.text)
- }
-
- }
|