123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- //
- // TSTextToastView.swift
- // TSLiveWallpaper
- //
- // Created by 100Years on 2025/6/16.
- //
- public let kTextToastShared = TSTextToastView.shared
- open class TSTextToastView {
-
- static let shared = TSTextToastView()
-
- public var clickViewHandle:(()->Void)?
-
- private lazy var textLabel:UILabel = {
- let textLabel = UILabel()
- textLabel.textColor = UIColor.white
- textLabel.text = "Save Successfully".localized
- textLabel.font = UIFont.font(size: 14)
- return textLabel
- }()
-
- private lazy var saveSuccessBg: UIView = {
- return creatSaveSuccessBg()
- }()
-
- lazy var loadingView: UIImageView = {
- let loadingView = UIImageView.createImageView(image:.textToastLoading)
- return loadingView
- }()
-
-
- private lazy var viewButton:UIView = {
- let color = UIColor.themeColor
- let viewButton = UIButton.createButton(title: "View".localized ,backgroundColor: color.withAlphaComponent(0.2),font: UIFont.font(size: 12),titleColor: color,corner: 14) { [weak self] in
- guard let self = self else { return }
- if let clickViewHandle = clickViewHandle {
- clickViewHandle()
- }
-
- DispatchQueue.main.async{
- self.saveSuccessBg.removeFromSuperview()
- self.loadingView.stopRotating()
- }
- }
- viewButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
- return viewButton
- }()
-
- func creatSaveSuccessBg() -> UIView {
- let view = UIView()
- view.frame = CGRect(x: 0, y: 0, width: 288, height: 48)
- // 阴影
- view.backgroundColor = .clear
- view.layer.shadowColor = UIColor.black.cgColor
- view.layer.shadowOffset = CGSize(width: 0, height: 2)
- view.layer.shadowOpacity = 0.1
-
- // 圆角
- let colorBg = UIView()
- colorBg.backgroundColor = "#333333".uiColor
- colorBg.layer.cornerRadius = 8
- colorBg.layer.masksToBounds = true
- colorBg.clipsToBounds = true
-
- view.addSubview(colorBg)
- colorBg.snp.makeConstraints { make in
- make.leading.trailing.top.bottom.equalTo(0)
- }
-
- view.addSubview(loadingView)
- view.addSubview(viewButton)
- view.addSubview(textLabel)
-
- loadingView.snp.makeConstraints { make in
- make.width.height.equalTo(24)
- make.centerY.equalToSuperview()
- make.leading.equalTo(12)
- }
-
- viewButton.snp.makeConstraints { make in
- make.width.equalTo(viewButton.intrinsicContentSize.width)
- make.height.equalTo(28)
- make.trailing.equalTo(-8)
- make.centerY.equalToSuperview()
- }
-
- textLabel.snp.makeConstraints { make in
- make.leading.equalTo(loadingView.snp.trailing).offset(8)
- make.trailing.equalTo(viewButton.snp.leading).offset(-8)
- make.centerY.equalToSuperview()
- }
-
- return view
- }
-
-
- public func getBottom(topY:CGFloat)->CGFloat{
- let bottom = -(k_ScreenHeight - 48 - topY)
- debugPrint("bottom=\(bottom)")
- return bottom
- }
-
- public func show(atView:UIView,text:String = "Process successfully".localized,deadline:Double = 5.0,bottom:CGFloat = -112,showViewBtn:Bool = true,clickViewHandle:(()->Void)? = nil) {
- self.clickViewHandle = clickViewHandle
- kExecuteOnMainThread {
- self.textLabel.text = text
- self.viewButton.isHidden = !showViewBtn
- atView.addSubview(self.saveSuccessBg)
- self.saveSuccessBg.snp.remakeConstraints { make in
- make.width.greaterThanOrEqualTo(288)
- make.width.lessThanOrEqualTo(k_ScreenWidth-32)
- make.height.equalTo(48)
- make.centerX.equalToSuperview()
- make.top.equalTo(k_Nav_Height + 10)
- }
-
- self.loadingView.startRotating()
- }
- DispatchQueue.main.asyncAfter(deadline: .now() + deadline) {
- self.saveSuccessBg.removeFromSuperview()
- self.loadingView.stopRotating()
- }
- }
-
-
- }
|