GLNotificationBar 2.3.5

GLNotificationBar 2.3.5

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年11月
SwiftSwift 版本3.1
SPM支持 SPM

gokul 维护。



  • 作者:
  • gokul

GLNotificationBar

CI Status
Version
License
Platform

注意:更新了 Xcode 9.0 & swift 4.0.

overView

备注

GLNotificationBar 是一个库,允许您轻易地创建出现在屏幕顶部的横幅通知,用于在活动状态下处理推送通知。用 xcode 8.3.1swift 3 构建。

示例

要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install

要求

GLNotificationBar 需要 iOS 8.0+。

安装

CocoaPods

GLNotificationBar 可通过 CocoaPods 获取。要安装它,只需将以下行添加到 Podfile
即可

pod 'GLNotificationBar'

手动

将文件 GLNotificationBar.swift & GLNotificationBar.xib 从 ~/GLNotificationBar/GLNotificationBar/Classes 复制到您的项目中。

用户指南

Swift

let notificationBar = GLNotificationBar(title: "Today Quote", message: "Yesterday is today's memory, and tomorrow is today's dream.", preferredStyle: .DetailedBanner, handler: nil)
notificationBar.addAction(GLNotifyAction(title: "Like", style: .Default, handler: { (action) in
   print("I Like this quote")
}))
notificationBar.addAction(GLNotifyAction(title: "Cancel", style: .Cancel, handler: nil))

Objective C

  • 运行 pod install。 pod 'GLNotificationBar'
  • 然后在 viewcontroller 类的顶部添加 @import GLNotificationBar;
  • 现在添加以下代码到您需要的地方。
    GLNotificationBar * notificationBar = [[GLNotificationBar alloc]initWithTitle:@"Today Quote" message:@"Yesterday is today's memory, and tomorrow is today's dream." preferredStyle:0 handler:nil];
    [notificationBar addAction:[[GLNotifyAction alloc]initWithTitle:@"Like" style:0 handler:^(GLNotifyAction * action) {
        NSLog(@"I Like this quote");
        //NSLog(@"Text reply %@",action.textResponse);
    }]];
    [notificationBar addAction:[[GLNotifyAction alloc]initWithTitle:@"Cancel" style:4 handler:nil]];
    

深入了解

  • GLNotificationBar 使用简单,实现方式类似于 UIAlertController

    let notificationBar = GLNotificationBar(title: "hallowean", message: "😎Hi there! We've missed you. Enjoy the new hallowean sticker,borders,bgs on your app.😈🎅🏻", preferredStyle: .DetailedBanner, handler: nil)
    
    

    这简单地展示了带有指定标题和消息的 GLNotificationBar,handler 可用来捕获通知条上的点击手势。通知条的默认行为是,点击时会自动消失。

存在两种类型的 GLNotificationBar 风格和五种类型的 GLNotifyAction

  • 详细横幅

    • .DetailedBanner 风格类似于 os10 风格的通知栏,向下滑动此类型的通知会在详情中打开,可能包括 GLNotifyAction's
      可以将 GLNotifyAction 添加到如下 GLNotificationBar

      let cancelButton = GLNotifyAction(title: "Cancel", style: .Cancel) { (result) in
            print(result.actionTitle)
         }
         notificationBar.addAction(cancelButton)
      

      或者

      notificationBar.addAction(GLNotifyAction(title: "Cancel", style: .Cancel) { (result) in
          print(result.actionTitle)
      })
      
    • GLNotifyAction 同样有四种不同类型,每种类型都执行相应的操作。

      public enum GLNotificationActionType {
         case Default  // Apply the default style to the action’s button.
         case Destructive  //Apply a style that indicates the action might change or delete data.
         case TextInput  //Apply a style that indicates the action opens an textinput field helps to respond notification as string.
         case OnlyTextInput  //Apply a style which removes all other action added and simply adds text field as input to respond notification.
         case Cancel  //Apply a style that indicates the action cancels the operation and leaves things unchanged.
      }
      

    detailedBanner

  • 简单横幅

    • .SimpleBanner 在外观上类似于 .DetailedBanner,但它有限制项。它不能向下滑动打开详细信息格式。
    • 添加到此类型通知栏的 GLNotifyAction 将不会得到考虑。

    simpleBanner

  • GLNotifyAction's .OnlyTextInput

     notificationBar.addAction(GLNotifyAction(title: "Reply", style: .OnlyTextInput) { (result) in
          print(result.textResponse)
       })
    
    • .OnlyTextInput 与其他动作类型有所不同。
    • 添加此操作会移除所有其他已添加的操作,并立即以用户输入选项的形式呈现文本框,无需任何用户交互。
    • 这有助于用户用文本响应当前通知。

    textInput_ActionType

  • notificationBar.showTime

     notificationBar.showTime(3.0)
    
    • 此方法可以帮助设置通知条隐藏的时间间隔。
    • 默认值是 5.0 秒。
    • 0.0可以用来自动隐藏通知栏的关闭。
  • notificationBar.notificationSound

     notificationBar.notificationSound("Your sound name", ofType: ".mp3", vibrate: true)
    
    • 默认情况下,GLNotificationBar不会播放任何声音,要播放通知声音,请添加此方法。
    • 此方法有助于在显示通知时播放通知声音。
    • 如果找不到所提及的声音文件,将播放系统默认声音。

作者

gokul,[email protected]

社交

许可证

GLNotificationBar在MIT许可下可用。有关更多信息,请参阅LICENSE文件。