WWToast

main

A small tool imitating Android's Toast function...
William-Weng/WWToast

WWToast

Swift-5.6 iOS-14.0 Swift Package Manager-SUCCESS LICENSE

  • A small tool imitating Android's Toast function...
  • 一個仿Android的Toast功能的小工具…

dependencies: [
    .package(url: "https://github.com/William-Weng/WWToast.git", .upToNextMajor(from: "1.1.0"))
]
函式 功能
makeText(target:text:duration:backgroundColor:textColor:height:) 顯示文字

Example

import UIKit
import WWPrint
import WWToast

final class ViewController: UIViewController {
    
    @IBOutlet var showToastLabels: [UILabel]!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initSetting()
    }
    
    @objc func showToast(_ recognizer: UITapGestureRecognizer) {
        
        guard let label = recognizer.view as? UILabel,
              let text = label.text
        else {
            return
        }
        
        WWToast.shared.makeText(target: self, text: text, backgroundColor: .red)
    }
}

// MARK: - WWToastDelegate
extension ViewController: WWToastDelegate {
    
    func willDisplay(window: WWToastWindow?, textList: [String], text: String?) {
        wwPrint("textList =? \(textList), text => \(text ?? "nil")")
    }
    
    func didDisplay(window: WWToastWindow?, textList: [String], text: String?) {
        wwPrint("textList =? \(textList), text => \(text ?? "nil")")
    }
    
    func willDismiss(window: WWToastWindow?, textList: [String], text: String?) {
        wwPrint("textList =? \(textList), text => \(text ?? "nil")")
    }

    func didDismiss(window: WWToastWindow?, textList: [String], text: String?) {
        wwPrint("textList =? \(textList), text => \(text ?? "nil")")
    }
}

// MARK: - 小工具
private extension ViewController {
    
    func initSetting() {
        
        WWToast.shared.delegate = self
        
        showToastLabels.forEach { label in
            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(Self.showToast(_:)))
            label.addGestureRecognizer(tapGesture)
        }
    }
}

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

Last updated: Thu Dec 05 2024 15:44:42 GMT-1000 (Hawaii-Aleutian Standard Time)