123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // BFSubtitleEditView.swift
- // BFRecordScreenKit
- //
- // Created by ak on 2021/12/8.
- //
- import Foundation
- import BFUIKit
- import BFFramework
- typealias EditSubtitleDone = (_ text: String) -> Void
- class BFSubtitleEditView: UIView {
- var editSubtitleDone:EditSubtitleDone?
-
- // var settingModel:BFSubtitileSettingModel = BFSubtitileSettingModel.init()
- /// 输入框
- lazy var textView: BFTextView = {
- let textView = BFTextView()
- textView.maxTextLength = 30
- textView.maxTextLengthRemind = ""
- textView.backgroundColor = UIColor.clear
- textView.textColor = UIColor.hexColor(hexadecimal: "#FFFFFF")
- textView.tintColor = UIColor.hexColor(hexadecimal: "#EE0051")
- textView.font = UIFont.systemFont(ofSize: 17)
- textView.placeHolder = ""
- textView.placeHolderColor = UIColor.hexColor(hexadecimal: "#555555")
- textView.delegate = self
-
- textView.textDidChangedHandle = { [weak self] textView in
-
- }
- if #available(iOS 11.0, *) {
- textView.contentInsetAdjustmentBehavior = .never
- }
- return textView
- }()
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
-
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- backgroundColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.7)
- addSubview(textView)
- textView.snp.makeConstraints { make in
- make.left.equalTo(37)
- make.width.equalTo(300)
- make.height.equalTo(280)
- make.top.equalToSuperview().offset(134)
- }
-
-
- let doneBtn = UIButton()
- doneBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#28BE67")
- doneBtn.setTitle("完成", for: .normal)
- doneBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
- doneBtn.addTarget(self, action: #selector(doneAction), for: .touchUpInside)
- doneBtn.addCorner(corner:4)
- addSubview(doneBtn)
- doneBtn.snp.makeConstraints { make in
- make.right.equalTo(-12)
- make.width.equalTo(60)
- make.height.equalTo(36)
- make.top.equalToSuperview().offset(48)
- }
-
- let cancelBtn = UIButton()
- cancelBtn.backgroundColor = .clear
- cancelBtn.setTitle("取消", for: .normal)
- cancelBtn.setTitleColor(.white, for: .normal)
- cancelBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
- cancelBtn.addTarget(self, action: #selector(cancelAction), for: .touchUpInside)
- addSubview(cancelBtn)
- cancelBtn.snp.makeConstraints { make in
- make.left.equalToSuperview().offset(12)
- make.width.equalTo(60)
- make.height.equalTo(36)
- make.top.equalToSuperview().offset(45)
- }
- }
-
- @objc func cancelAction(){
- self.isHidden = true
- textView.resignFirstResponder()
- }
-
- @objc func doneAction(){
- self.isHidden = true
- textView.resignFirstResponder()
- if(editSubtitleDone != nil){
- BFLog(message: "最后修改的文字为:\(String(describing: textView.text))")
- editSubtitleDone!(textView.text)
- }
- }
-
- func setNewText(text:String) {
-
- textView.text = text.substring(to: 30)
- // BFLog(message: "传值\(textView.text)")
- //
- // let attributedText = NSMutableAttributedString(string: textView.text,attributes: [.font: UIFont.systemFont(ofSize: CGFloat(settingModel.subtitleSize) * 375 / 1080),.strokeWidth:-6,.strokeColor: settingModel.strokeColor,.foregroundColor:settingModel.fontColor])
- // textView.attributedText = attributedText
-
- }
- }
- extension BFSubtitleEditView: UITextViewDelegate{
-
- func textViewDidBeginEditing(_ textView: UITextView) {
-
- }
- func textViewDidEndEditing(_ textView: UITextView) {
-
- BFLog(message: "textViewDidEndEditing 输入完成 \(textView.text ?? "")")
- }
- func textView(_: UITextView, shouldChangeTextIn _: NSRange, replacementText text: String) -> Bool {
- if text.isEmoji() {
- cShowHUB(superView: nil, msg: "不能输入表情")
- return false
- }
- // BFLog(message: "inputText \(String(describing: textView.text))")
-
- return true
- }
- }
|