You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.9 KiB
98 lines
2.9 KiB
import UIKit
|
|
|
|
public class PlayerView: UIView {
|
|
private let titleLabel: UILabel = UILabel()
|
|
private let langLabel: UILabel = UILabel()
|
|
private let cnLabel: UILabel = UILabel()
|
|
private let enLabel: UILabel = UILabel()
|
|
private let stackView: UIStackView
|
|
|
|
public override init(frame: CGRect) {
|
|
stackView = UIStackView()
|
|
super.init(frame: frame)
|
|
setupUI()
|
|
}
|
|
|
|
public convenience init() {
|
|
self.init(frame: .zero)
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
stackView = UIStackView()
|
|
super.init(coder: coder)
|
|
setupUI()
|
|
}
|
|
|
|
private func setupUI() {
|
|
backgroundColor = .white
|
|
|
|
titleLabel.text = "实时翻译"
|
|
titleLabel.font = .boldSystemFont(ofSize: 22)
|
|
titleLabel.textColor = .black
|
|
titleLabel.textAlignment = .center
|
|
titleLabel.numberOfLines = 1
|
|
|
|
langLabel.text = "中文(简体) -> 英语"
|
|
langLabel.font = .systemFont(ofSize: 14)
|
|
langLabel.textColor = .darkGray
|
|
langLabel.textAlignment = .left
|
|
langLabel.numberOfLines = 1
|
|
|
|
cnLabel.font = .systemFont(ofSize: 18)
|
|
cnLabel.textColor = .black
|
|
cnLabel.textAlignment = .left
|
|
cnLabel.numberOfLines = 0
|
|
|
|
enLabel.font = .systemFont(ofSize: 18)
|
|
enLabel.textColor = UIColor(red: 0.24, green: 0.54, blue: 0.90, alpha: 1.0)
|
|
enLabel.textAlignment = .left
|
|
enLabel.numberOfLines = 0
|
|
|
|
let para = NSMutableParagraphStyle()
|
|
para.lineSpacing = 4
|
|
cnLabel.attributedText = NSAttributedString(string: "正在识别...", attributes: [.paragraphStyle: para])
|
|
enLabel.attributedText = NSAttributedString(string: "翻译中...", attributes: [.paragraphStyle: para])
|
|
|
|
stackView.axis = .vertical
|
|
stackView.spacing = 12
|
|
stackView.alignment = .fill
|
|
stackView.distribution = .fill
|
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
stackView.addArrangedSubview(titleLabel)
|
|
stackView.addArrangedSubview(langLabel)
|
|
stackView.addArrangedSubview(cnLabel)
|
|
stackView.addArrangedSubview(enLabel)
|
|
|
|
layoutMargins = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
|
addSubview(stackView)
|
|
|
|
let guide = layoutMarginsGuide
|
|
NSLayoutConstraint.activate([
|
|
stackView.topAnchor.constraint(equalTo: guide.topAnchor),
|
|
stackView.leadingAnchor.constraint(equalTo: guide.leadingAnchor),
|
|
stackView.trailingAnchor.constraint(equalTo: guide.trailingAnchor),
|
|
stackView.bottomAnchor.constraint(lessThanOrEqualTo: guide.bottomAnchor),
|
|
])
|
|
}
|
|
|
|
public func play() {
|
|
}
|
|
|
|
public func pause() {
|
|
}
|
|
|
|
public func update(withLang lang: String?, cn: String?, en: String?) {
|
|
if let lang = lang {
|
|
langLabel.text = lang
|
|
}
|
|
let para = NSMutableParagraphStyle()
|
|
para.lineSpacing = 4
|
|
if let cn = cn {
|
|
cnLabel.attributedText = NSAttributedString(string: cn, attributes: [.paragraphStyle: para])
|
|
}
|
|
if let en = en {
|
|
enLabel.attributedText = NSAttributedString(string: en, attributes: [.paragraphStyle: para])
|
|
}
|
|
}
|
|
}
|
|
|
|
|