TSViewTool.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // TSViewTool.swift
  3. // TSLiveWallpaper
  4. //
  5. // Created by 100Years on 2024/12/20.
  6. //
  7. class TSViewTool: UIView {
  8. static func createNormalSubmitBtn(title:String, imageNamed:String? = nil, action: (() -> Void)? = nil) -> UIButton {
  9. let image = UIImage(named:imageNamed ?? "")
  10. let btn = UIButton.createButton(title:title,image: image,font: UIFont.font(size: 18,weight: .medium),titleColor:"#010101".color,action: action)
  11. var buttonBgImage = UIImage(named: "normal_submit_bg")!
  12. // if UIDevice.isPad {
  13. // buttonBgImage = buttonBgImage.resizableImage(withCapInsets: UIEdgeInsets(top:24, left: 24, bottom: 24, right: 24), resizingMode: .stretch)
  14. // }
  15. btn.setBackgroundImage(buttonBgImage, for: .normal)
  16. // kDelayMainShort {
  17. // btn.addGradientBg(colors: ["#B3FFAB".color.cgColor,"12FFF7".color.cgColor],startPoint: CGPoint(x: 0, y: 1),endPoint: CGPoint(x: 1, y: 0))
  18. // }
  19. if image != nil {
  20. btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -8, bottom: 0, right: 0)
  21. btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0)
  22. }
  23. return btn
  24. }
  25. static func setNormalSubmitBtn(btn:UIButton,showVip:Bool) {
  26. if showVip{
  27. btn.setImage(UIImage(named: "vip_icon"), for: .normal)
  28. btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -8, bottom: 0, right: 0)
  29. btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0)
  30. }else{
  31. btn.setImage(nil, for: .normal)
  32. btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  33. btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  34. }
  35. }
  36. static func createBlurEffectView(style:UIBlurEffect.Style,backgroundColor:UIColor? = nil) -> UIVisualEffectView {
  37. let blurEffect = UIBlurEffect(style: style)
  38. let blurEffectView = UIVisualEffectView(effect: blurEffect)
  39. blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  40. if backgroundColor != nil {
  41. blurEffectView.backgroundColor = backgroundColor
  42. }
  43. return blurEffectView
  44. }
  45. }
  46. let kWapppaperPlaceholderImage = UIImage(named: "wapppaper_placeholder")
  47. let KIconLiveImage = UIImage(named: "icon_live")
  48. let kSavePhotoSuccesswShared = TSSavePhotoSuccessTool.shared
  49. class TSSavePhotoSuccessTool {
  50. static let shared = TSSavePhotoSuccessTool()
  51. private lazy var textLabel:UILabel = {
  52. let textLabel = UILabel()
  53. textLabel.textColor = "#4A5178".color
  54. textLabel.text = "Save Successfully".localized
  55. textLabel.font = UIFont.font(size: 14)
  56. return textLabel
  57. }()
  58. private lazy var saveSuccessBg: UIView = {
  59. return creatSaveSuccessBg()
  60. }()
  61. func creatSaveSuccessBg() -> UIView {
  62. let view = UIView()
  63. view.frame = CGRect(x: 0, y: 0, width: 288, height: 48)
  64. // 阴影
  65. view.backgroundColor = .clear
  66. view.layer.shadowColor = UIColor.black.cgColor
  67. view.layer.shadowOffset = CGSize(width: 0, height: 2)
  68. view.layer.shadowOpacity = 0.1
  69. // 圆角
  70. let colorBg = UIView()
  71. colorBg.backgroundColor = .white
  72. colorBg.layer.cornerRadius = 8
  73. colorBg.layer.masksToBounds = true
  74. colorBg.clipsToBounds = true
  75. view.addSubview(colorBg)
  76. colorBg.snp.makeConstraints { make in
  77. make.leading.trailing.top.bottom.equalTo(0)
  78. }
  79. let image = UIImage(named: "success_icon")
  80. let iconView = UIImageView(image: image)
  81. view.addSubview(iconView)
  82. iconView.snp.makeConstraints { make in
  83. make.width.height.equalTo(24)
  84. make.centerY.equalToSuperview()
  85. make.leading.equalTo(12)
  86. }
  87. view.addSubview(textLabel)
  88. let viewButton = UIButton.createButton(title: "View".localized ,backgroundColor: "4FEA9D".toColor()?.withAlphaComponent(0.2),font: UIFont.font(size: 14),titleColor: "4FEA9D".toColor(),corner: 14) {
  89. if let url = URL(string: "photos-redirect://") {
  90. if UIApplication.shared.canOpenURL(url) {
  91. UIApplication.shared.open(url, options: [:], completionHandler: nil)
  92. playVibration()
  93. }
  94. }
  95. }
  96. view.addSubview(viewButton)
  97. viewButton.snp.makeConstraints { make in
  98. make.width.equalTo(65)
  99. make.height.equalTo(28)
  100. make.trailing.equalTo(-8)
  101. make.centerY.equalToSuperview()
  102. }
  103. textLabel.snp.makeConstraints { make in
  104. make.leading.equalTo(iconView.snp.trailing).offset(8)
  105. make.trailing.equalTo(viewButton.snp.leading).offset(-4)
  106. make.centerY.equalToSuperview()
  107. }
  108. return view
  109. }
  110. func show(atView:UIView,text:String = "Save Successfully".localized) {
  111. kExecuteOnMainThread {
  112. self.textLabel.text = text
  113. atView.addSubview(self.saveSuccessBg)
  114. self.saveSuccessBg.snp.remakeConstraints { make in
  115. make.width.equalTo(288)
  116. make.height.equalTo(48)
  117. make.centerX.equalToSuperview()
  118. make.top.equalTo(k_Height_statusBar()+56.0)
  119. }
  120. }
  121. DispatchQueue.main.asyncAfter(deadline: .now()+5.0) {
  122. self.saveSuccessBg.removeFromSuperview()
  123. }
  124. }
  125. }