JDStatusBarNotification

main

Highly customizable & feature rich notifications displayed below the status bar. iOS 13+. Swift ready!
calimarkus/JDStatusBarNotification

JDStatusBarNotification

Highly customizable & feature rich notifications displayed below the status bar. Customizable colors, fonts & animations. Supports notch and no-notch devices, landscape & portrait layouts and Drag-to-Dismiss. Can display a subtitle, an activity indicator, a progress bar & custom views out of the box. iOS 13+. Swift ready!

Please open a Github issue, if you think anything is missing or wrong.

Here's some examples of the possibilities (the pill style is the default):

examples

Full-Width styles in action (the pill styles support the same features / animations):

Drag to dismiss Activity & Progress Bars Custom styles
1 3 2
Landscape apps (device rotation also supported)
landscape

Installation

  • SwiftPM:
    • Xcode -> File -> Add packages: git@github.com:calimarkus/JDStatusBarNotification.git
  • CocoaPods:
    • pod 'JDStatusBarNotification'
  • Carthage:
    • github "calimarkus/JDStatusBarNotification"
  • Manually:
    • Copy the JDStatusBarNotification/JDStatusBarNotification folder into your project.

Documentation

Find the class documentation hosted on Github.

Changelog

See CHANGELOG.md

Usage

NotificationPresenter is a singleton. You don't need to initialize it anywhere. All examples are Swift code, but the class can be used in Objective-C as well. Also checkout the example project, which has many examples and includes a convenient style editor.

Here's some usage examples:

Showing a text notification

It's as simple as this:

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

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

Dismissing a notification

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

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

Showing progress

progress

NotificationPresenter.shared().displayProgressBar(percentage: 0.5)

// or animated
NotificationPresenter.shared().animateProgressBar(toPercentage: 1.0, animationDuration: 1.0) { presenter in
   // ...
}

Showing activity

activity

NotificationPresenter.shared().displayActivityIndicator(true)

Using alternative styles

There's a few included styles you can easily use with the following API:

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

Troubleshooting

No notifications are showing up

If your app uses a UIWindowScene the NotificationPresenter needs to know about it before you present any notifications. The library attempts to find the correct WindowScene automatically, but that might fail. If it fails no notifications will show up at all. You can explicitly set the window scene to resolve this:

NotificationPresenter.shared().setWindowScene(windowScene)

Customization

You have the option to create fully customized styles - or to even present custom views.

The closures of updateDefaultStyle() and addStyle(styleName: String) provide a copy of the default style, which can then be modified. See the JDStatusBarStyle class (or the style editor in the example project) for all options and documentation. You can also use the example project's style editor to create a style visually and then export the code to configure that style.

// 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

Checkout the example project, which contains a full style editor. You can tweak all customization options within the app, see the changes live and even export the configuration code.

style-editor

Custom View

customView customView2

// present a custom view
var anyView: UIView = ...
NotificationPresenter.shared().present(customView: anyView)

Background Styles

There's two supported background styles:

typedef NS_ENUM(NSInteger, JDStatusBarBackgroundType) {
  /// The background covers the full display width and the full status bar & navbar height.
  JDStatusBarBackgroundTypeFullWidth,
  /// The background is a floating pill around the text.
  JDStatusBarBackgroundTypePill,
} NS_SWIFT_NAME(BarBackgroundType);

Animation Types

The supported animation types:

typedef NS_ENUM(NSInteger, JDStatusBarAnimationType) {
  /// Notification will move in from the top, and move out again to the top
  JDStatusBarAnimationTypeMove,
  /// Notification will fall down from the top and bounce a little bit
  JDStatusBarAnimationTypeBounce,
  /// Notification will fade in and fade out
  JDStatusBarAnimationTypeFade,
} NS_SWIFT_NAME(BarAnimationType);

Twitter

I'm @calimarkus on Twitter. Feel free to post a tweet, if you like JDStatusBarNotification.

tweetbutton

Credits

Originally based on KGStatusBar by Kevin Gibbon

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Jun 29 2022 08:37:01 GMT-0500 (GMT-05:00)