몇 번 꺼도 소용없어요.

5857 단어 Swift
어리석은 짓을 하고도 후회하지 않는다.

방법


다음 보기 컨트롤러를 만듭니다.
AsciiAlertController.swift
import UIKit

class AsciiAlertController: UIAlertController {
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        for label in findLabels(in: view) {
            label.textAlignment = .left
            label.font = UIFont.monospacedDigitSystemFont(ofSize: label.font.pointSize, weight: .regular)
        }
    }

    func findLabels(in view: UIView) -> [UILabel] {
        return view.subviews.flatMap({ subview -> [UILabel] in
            if let label = subview as? UILabel {
                return [label] + findLabels(in: label)
            } else {
                return findLabels(in: subview)
            }
        })
    }
}

다음과 같이 호출합니다
ViewController.swift
    func showAlert() {
        let message = """
 ∧_∧ ババババ
( ・ω・)=つ≡つ
(っ ≡つ=つ
`/  )
(ノΠU
何回閉じても無駄ですよ?ww
m9(^Д^)プギャー!!
"""

        let dialog = AsciiAlertController(title: nil, message: message, preferredStyle: .alert)
        dialog.addAction(UIAlertAction(title: "閉じる", style: .default, handler: { _ in
            self.showAlert()
        }))
        show(dialog, sender: nil)
    }

방법을 강구하는 곳

  • AA를 표시하기 위해 UIAlertViewController의 UILAbel 모두 왼쪽 정렬
  • 또한 등폭 글씨체를 사용했다(이것은 하지 않아도 변함이 없다)
  • 컨디션

  • Xcode: 10.1
  • macOS 10.14 (Mojave)
  • 좋은 웹페이지 즐겨찾기