JDStatusBarNotification 2.2.2

JDStatusBarNotification 2.2.2

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2024年3月

Markus Emrich 维护。




  • Markus Emrich

JDStatusBarNotification

高度可定制的功能丰富的通知,显示在状态栏下方。可自定义颜色、字体和动画。支持刘海和普通尺寸的设备,横竖屏布局,以及拖拽关闭。可显示子标题、活动指示器、进度条和自定义视图。iOS 13+。Swift 兼容!

如果您认为有任何缺失或错误,请提交 GitHub 事项

以下是可能性的示例(药丸样式是默认样式)

examples

全宽样式正在运行中(药丸样式支持相同的功能/动画)

拖拽关闭 活动和进度条 自定义样式
1 3 2
横屏应用(也支持设备旋转)
landscape

安装

  • SwiftPM
    • Xcode -> 文件 -> 添加包: [email protected]:calimarkus/JDStatusBarNotification.git
  • CocoaPods
    • pod 'JDStatusBarNotification'
  • Carthage
    • github "calimarkus/JDStatusBarNotification"
  • 手动
    • JDStatusBarNotification/JDStatusBarNotification 文件夹复制到您的项目中。

文档

在Github上找到类文档

更新日志

请参见CHANGELOG.md

入门指南

NotificationPresenter 是一个单例。你不需要在任何地方初始化它。所有示例都是Swift代码,但这个类也可以在Objective-C中使用。此外,还可以查看示例项目,该项目包含许多示例并包含方便的样式编辑器。

以下是一些使用示例

显示文本通知

就像这样简单

NotificationPresenter.shared().present(text: "Hello World")

// with completion
NotificationPresenter.shared().present(text: "Hello World") { presenter in
   // ...
}

取消通知

NotificationPresenter.shared().dismiss(animated: true)

// with completion
NotificationPresenter.shared().dismiss(afterDelay: 0.5) { presenter in
   // ...
}

显示活动

activity

NotificationPresenter.shared().present(text: "")
NotificationPresenter.shared().displayActivityIndicator(true)

显示自定义左侧视图

leftview

let image = UIImageView(image: UIImage(systemName: "gamecontroller.fill"))
NotificationPresenter.shared().present(title: "Player II", subtitle: "Connected")
NotificationPresenter.shared().displayLeftView(image)

显示进度

progress

NotificationPresenter.shared().present(text: "Animating Progress…") { presenter in
  presenter.animateProgressBar(toPercentage: 1.0, animationDuration: 0.75) { presenter in
    presenter.dismiss()
  }
}

// or set an explicit percentage manually (without animation)
NotificationPresenter.shared().displayProgressBar(percentage: 0.0)

使用其他包含的样式

可以使用以下API轻松使用以下包含的样式。

itworks

NotificationPresenter.shared().present(text: "Yay, it works!", includedStyle: .success)

使用自定义UIView

如果想要完全控制通知内容和样式,可以使用自己的自定义UIView。

customView customView2

// present a custom view
let button = UIButton(type: .system, primaryAction: UIAction { _ in
  NotificationPresenter.shared().dismiss()
})
button.setTitle("Dismiss!", for: .normal)
NotificationPresenter.shared().present(customView: button)

自定义

您可以选择轻松创建和使用完全自定义的样式。

“updateDefaultStyle()” 和 “addStyle(styleName: String)” 的闭包提供了默认样式的副本,然后可以进行修改。有关所有选项,请参阅 JDStatusBarStyle 类文档

// update default style
NotificationPresenter.shared().updateDefaultStyle { style in
   style.backgroundStyle.backgroundColor = .red
   style.textStyle.textColor = .white
   style.textStyle.font = UIFont.preferredFont(forTextStyle: .title3)
   // and many more options
   return style
}

// set a named custom style
NotificationPresenter.shared().addStyle(styleName: "xxx") { style in
   // ...
   return style
}

样式编辑器

或者查看示例项目,其中包含完整的样式编辑器。您可以在应用程序内调整所有自定义选项,实时查看更改,甚至将新创建样式的配置代码导出以便轻松在应用程序中使用。

style-editor

背景样式

支持两种背景样式

/// The background is a floating pill around the text. The pill size and appearance can be customized. This is the default.
StatusBarNotificationBackgroundType.pill
/// The background covers the full display width and the full status bar + navbar height.
StatusBarNotificationBackgroundType.fullWidth

动画类型

支持的动画类型

/// Slide in from the top of the screen and slide back out to the top. This is the default.
StatusBarNotificationAnimationType.move,
/// Fade-in and fade-out in place. No movement animation.
StatusBarNotificationAnimationType.fade,
/// Fall down from the top and bounce a little bit, before coming to a rest. Slides back out to the top.
StatusBarNotificationAnimationType.bounce,

故障排除

没有显示通知

如果你的应用使用 UIWindowScene,则在显示任何通知之前,NotificationPresenter 需要知道它。库自动尝试找到正确的 WindowScene,但可能会失败。如果失败了,将不会显示任何通知。你可以显式设置窗口场景以解决这个问题

NotificationPresenter.shared().setWindowScene(windowScene)

推特

我在推特上 @calimarkus。如果你喜欢 JDStatusBarNotification,请随时 发表一条推文

tweetbutton

致谢

最初基于 Kevin Gibbon 的 KGStatusBar 开发