ZTDropDownNotification 1.0.1

ZTDropDownNotification 1.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Aug 2017

Maintained by Zhang Tao.



  • By
  • Zhang Tao

ZTDropDownNotification is a notification class that displays a drop-down notification from top edge of key window and dismisses it after a duration. The default layouts can display message only or message with icon. It also supports custom layout and displays custom view directly. The notification is inspired by Mobile QQ, aiming to provide a handy way to show notifications.

Requirements

ZTDropDownNotification works on iOS 8+. It depends on the following Apple frameworks, which should already be included with most Xcode templates:

  • Foundation.framework
  • UIKit.framework

You will need the latest developer tools in order to build ZTDropDownNotification. Old Xcode versions might work, but compatibility will not be explicitly maintained.

Usage

Notify Message Only

Swift:

  ZTDropDownNotification.notifyMessage("content", withIcon: nil)

Ojbective-C:

  [ZTDropDownNotification notifyMessage:@"content" withIcon:nil];

Shortcut Notifying Messages

Shortcut notifying methods use ZTNInfoIconKey, ZTNSuccessIconKey and ZTNFailureIconKey to get corresponding icon.

For example, register ZTNSuccessIconKey icon as following:

Swift:

  ZTDropDownNotification.registerIcons([
      ZTNSuccessIconKey: #imageLiteral(resourceName:"check_green")])

Ojbective-C:

  [ZTDropDownNotification registerIcons:@{
      ZTNSuccessIconKey: [UIImage imageNamed:@"check_green"]
      }];

And then notifySuccessMessage: method works as expected:

Swift:

  ZTDropDownNotification.notifySuccessMessage("content")

Ojbective-C:

  [ZTDropDownNotification notifySuccessMessage:@"content"];

Note:
It will "notify message only" if the corresponding icon isn't registered before.

Notify Message with Custom Registered Icon

Swift:

  ZTDropDownNotification.notifyMessage("content", withIconKey: "ExampleIconKey")

Ojbective-C:

  [ZTDropDownNotification notifyMessage:@"content" withIconKey:@"ExampleIconKey"];

Notify Message with Temporary Icon

Swift:

  ZTDropDownNotification.notifyMessage("content", withIcon: #imageLiteral(resourceName:"thumbs_up_blue"))

Ojbective-C:

  [ZTDropDownNotification notifyMessage:@"content" withIcon:[UIImage imageNamed:@"thumbs_up_blue"]];

Set Custom Layout as Default Layout

Swift:

  ZTDropDownNotification.setCustomLayoutGenerator { () -> UIView in
      return CustomLayout.init()
    }

Ojbective-C:

  [ZTDropDownNotification setCustomLayoutGenerator:^UIView <ZTNLayout> * {
    return [CustomLayout new];
  }];

Note:
Due to current implementation(1.0.0), custom layout and view should leave an extra 8pt height area on top of the real content area.

Reset to Built-in Layouts

Swift:

  ZTDropDownNotification.setCustomLayoutGenerator(nil)

Ojbective-C:

  [ZTDropDownNotification setCustomLayoutGenerator:nil];

Notify Custom Temporary View

Swift:

  ZTDropDownNotification.notify(view)

Ojbective-C:

  [ZTDropDownNotification notifyView:view];

Note:
Due to current implementation(1.0.0), custom layout and view should leave an extra 8pt height area on top of the real content area.

TODO

  • [ ] Add unit tests.
  • [ ] Integrate Travis CI.
  • [ ] Find a better solution to avoid the spring animation on the top edge when the view shows totally.
  • [x] Support Swift.

License

Released under MIT license.