123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- //
- // BFSubtitleEditView.swift
- // BFRecordScreenKit
- //
- // Created by ak on 2021/12/8.
- //
- import BFCommonKit
- import BFMediaKit
- import BFUIKit
- import Foundation
- typealias EditSubtitleDone = (_ text: String,_ index:Int) -> Void
- //字幕最大数限制
- //public let subtitleMaxlength:Int = 0
- class BFSubtitleEditView: UIView {
-
- var showSubtitleIndex = 0
- var editSubtitleDone: EditSubtitleDone?
- // var settingModel:BFSubtitileSettingModel = BFSubtitileSettingModel.init()
- /// 输入框
- lazy var textView: BFTextView = {
- let textView = BFTextView()
- textView.maxTextLengthRemind = ""
- textView.backgroundColor = UIColor.clear
- textView.textColor = UIColor.hexColor(hexadecimal: "#FFFFFF")
- textView.tintColor = UIColor.hexColor(hexadecimal: "#389AFF")
- textView.font = UIFont.systemFont(ofSize: 17)
- textView.placeHolder = ""
- textView.placeHolderColor = UIColor.hexColor(hexadecimal: "#555555")
- textView.delegate = self
- textView.textDidChangedHandle = { [weak self] _ 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(red: 0, green: 0, blue: 0, alpha: 0.7)
- addSubview(textView)
- addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(doneAction)))
- 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: "#389AFF")
- doneBtn.setTitle("option_done".BFLocale, 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("option_cancel".BFLocale, 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() {
- isHidden = true
- textView.resignFirstResponder()
- }
- @objc func doneAction() {
- isHidden = true
- textView.resignFirstResponder()
- if editSubtitleDone != nil {
- BFLog(message: "最后修改的文字为:\(String(describing: textView.text))")
- editSubtitleDone!(textView.text,showSubtitleIndex)
- }
- }
- func setNewText(text: String,index:Int) {
- showSubtitleIndex = index
- textView.text = text
- // 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(_: 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: "option_fail_emoji".BFLocale)
- return false
- }
-
- // BFLog(message: "inputText \(String(describing: textView.text))")
-
- return true
- }
- }
|