通知Toast

一个旨在模仿 iOS 默认 Toast 消息视图的视图。

标题 图标 副标题
Title Icon Subtitle

用法

使用 SPM 或 Cocoapods 将此库添加到您的项目中。

要获得简洁的“Apple 风格”,您只需这样做

UIKit

import NotificationToast

let toast = ToastView(title: "Safari pasted from Notes")
toast.show()

该视图还包含许多可选的可自定义属性

let toast = ToastView(
    title: "Airpods Pro",
    titleFont: .systemFont(ofSize: 13, weight: .regular),
    subtitle: "Connected",
    subtitleFont: .systemFont(ofSize: 11, weight: .light),
    icon: UIImage(systemName: "airpodspro"),
    iconSpacing: 16,
    position: .bottom,
    onTap: { print("Tapped!") }
)
toast.show()

您可以同时显示该视图并带有触觉反馈(默认为 nil

toast.show(haptic: .success)

SwiftUI

    @State var isPresented = false

    Button("Present toast") {
        isPresented = true
    }
    .toast(isPresented: $isPresented, title: "Safari pasted from Notes")

与 UIKit 类似,您可以使用可选参数自定义视图(请查看自动完成功能以获取所有选项)

    @State var isPresented = false

    Button("Present toast") {
        isPresented = true
    }
    .toast(isPresented: $isPresented, title: "AirPods Pro", subtitle: "Connected", icon: UIImage(systemName: "airpodspro"))

贡献

由于这是我的第一个“UI”包,我相信它可以得到很大的改进,欢迎提交 PR 😊

替代方案

Drops 💧: https://github.com/omaralbeik/Drops
Bauly : https://github.com/wiencheck/Bauly