ASGeneratorErrorView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // ASGeneratorErrorView.swift
  3. // AICalendarWallpaper
  4. //
  5. // Created by 100Years on 2025/5/26.
  6. //
  7. class ASGeneratorErrorView: AIBaseView {
  8. var style:ASGeneratorView.Style = .generalError{
  9. didSet{
  10. debugPrint("ASGeneratorErrorView style = \(style)")
  11. switch style {
  12. case .sensitiveError:
  13. sensitiveErrorView()
  14. case .netWorkError:
  15. netWorkErrorView()
  16. default:
  17. generalErrorView()
  18. }
  19. }
  20. }
  21. var isUploadImage:Bool = true
  22. lazy var cusStackView: UIStackView = {
  23. let cusStackView = UIStackView()
  24. cusStackView.axis = .vertical
  25. cusStackView.distribution = .fill
  26. cusStackView.alignment = .center
  27. return cusStackView
  28. }()
  29. lazy var errorImageView: UIImageView = {
  30. let errorImageView = UIImageView.createImageView(imageName: "yellow_warning")
  31. return errorImageView
  32. }()
  33. lazy var textLabel: UILabel = {
  34. let textLabel = UILabel.createLabel(font: .font(size: 14),textColor: .white,textAlignment: .center,numberOfLines: 0)
  35. return textLabel
  36. }()
  37. lazy var submitBtn: UIButton = {
  38. let textColor = "#B48EFF".uiColor
  39. let btn = UIButton.createBtn(title: "Generate in the background".localized,font: .font(size: 16),titleColor: textColor,corner: 24)
  40. btn.layer.borderColor = textColor.cgColor
  41. btn.layer.borderWidth = 1.0
  42. btn.titleLabel?.adjustsFontSizeToFitWidth = true
  43. return btn
  44. }()
  45. override func setupViews() {
  46. contentView.addSubview(cusStackView)
  47. cusStackView.snp.makeConstraints { make in
  48. make.edges.equalToSuperview()
  49. }
  50. cusStackView.addArrangedSubview(errorImageView)
  51. errorImageView.snp.makeConstraints { make in
  52. make.top.equalTo(0)
  53. make.width.height.equalTo(56)
  54. }
  55. cusStackView.addSpacing(length: 12.0)
  56. cusStackView.addArrangedSubview(textLabel)
  57. textLabel.snp.makeConstraints { make in
  58. make.leading.equalTo(24)
  59. make.trailing.equalTo(-24)
  60. }
  61. cusStackView.addSpacing(length: 28.0)
  62. cusStackView.addArrangedSubview(submitBtn)
  63. submitBtn.snp.makeConstraints { make in
  64. make.width.equalTo(250)
  65. make.height.equalTo(48)
  66. make.bottom.equalTo(0)
  67. }
  68. }
  69. }
  70. extension ASGeneratorErrorView {
  71. func sensitiveErrorView() {
  72. submitBtn.setTitle(isUploadImage ? "Reselect photos".localized : "Got it".localized, for: .normal)
  73. // errorImageView.image = UIImage(named: "yellow_warning")
  74. errorImageView.image = .generationFailed
  75. errorImageView.snp.updateConstraints { make in
  76. make.width.height.equalTo(56)
  77. }
  78. textLabel.text = "Your photo may contain nudity, gore or violence that does not comply with the health policy, please replace the photo and try again.".localized
  79. }
  80. func generalErrorView() {
  81. submitBtn.setTitle("Got it".localized, for: .normal)
  82. errorImageView.image = .generationFailed
  83. errorImageView.snp.updateConstraints { make in
  84. make.width.height.equalTo(120)
  85. }
  86. textLabel.text = "Sorry there was a slight problem with the image processing, please try again later.".localized
  87. }
  88. func netWorkErrorView() {
  89. submitBtn.setTitle("Try Again".localized, for: .normal)
  90. errorImageView.image = UIImage(named: "network_error")
  91. errorImageView.snp.updateConstraints { make in
  92. make.width.height.equalTo(120)
  93. }
  94. textLabel.text = "No network, please check your network and try again.".localized
  95. }
  96. }