登录 立即注册
金钱:

GLNotificationBar 自定义通知框架

来自: Torr 分类: iOS精品源码 上传时间: 2016-11-24 11:56:17

项目介绍:

GLNotificationBar

自定义通知样式框架,多种自定义方案

https://github.com/gokulgovind/GLNotificationBar

Version: 1.2.1, Language: Swift 2.2

Author: Gokul @gokulgovind

overView

Note

GLNotificationBar is a library that allows you to easily create banner notifications that appear on top of screen, used to handle push notification in active state.Made with xcode 7.3.1 and swift 2.2

GLNotificationBar,它允许你轻松地创建出现在屏幕顶部的横幅通知,用于处理活动状态的推送通知。
使用xcode 7.3.1swift 2.2

Requirements 环境需求

GLNotificationBar requires iOS 8.0+.

Installation 安装方法

CocoaPods

GLNotificationBar is available through CocoaPods. To install
it, simply add the following line to your Podfile:

使用 Cocoapods 安装,只需要在podfile中添加以下一行
pod 'GLNotificationBar'

Manual手动安装

Copy the file GLNotificationBar.swift & GLNotificationBar.xib from ~/GLNotificationBar/GLNotificationBar/Classes to your project.

从路径~/GLNotificationBar/GLNotificationBar/Classes拷贝GLNotificationBar.swift & GLNotificationBar.xib到你的项目中去

User Guide 用户指南,多种自定义样式

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:

  • Run pod install. pod 'GLNotificationBar'

  • Then add @import GLNotificationBar; at top of your viewcontroller class.

  • Now add following code wherever you want.

    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]];

Diving In Depth

  • GLNotificationBar is simple to use,implementation is similar to 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)
    

This simply presents GLNotificationBar with given title and message,handler can be used to catch tap gesture on notification bar. The default behavior of notification bar is, dismissed automatically when tapped on it.

There are two types of GLNotificationBar style and Five type of GLNotifyAction types.

  • .DetailedBanner

    • .DetailedBanner style is similar to ios10 style notification bar, swiping down this type of notification open's in detail, which may include GLNotifyAction's
      GLNotifyAction can be added to GLNotificationBar as follows

let cancelButton = GLNotifyAction(title: "Cancel", style: .Cancel) { (result) in
      print(result.actionTitle)
   }
   notificationBar.addAction(cancelButton)
  **OR**
notificationBar.addAction(GLNotifyAction(title: "Cancel", style: .Cancel) { (result) in
    print(result.actionTitle)
})
  • GLNotifyAction also has four different types each performs their respective action.

    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

    • .SimpleBanner is similar to .DetailedBanner in appearance, but it's options are restricted. It can't be swiped down to open in detail form.

    • GLNotifyAction added to this type of notification bar will not be taken into account.

simpleBanner

  • GLNotifyAction's .OnlyTextInput

     notificationBar.addAction(GLNotifyAction(title: "Reply", style: .OnlyTextInput) { (result) in
          print(result.textResponse)
       })
    • .OnlyTextInput is some what different from other action types.

    • Adding this action removes all other action added and stight away presents textfield as option for user input without any user interaction.

    • This helps user to repond to a notification with text.

textInput_ActionType

  • notificationBar.showTime

     notificationBar.showTime(3.0)
    • This method helps to set time interval for notification bar to hide.

    • The default value is 5.0 seconds.

    • And 0.0 can used to turn off auto hide of notification bar.

  • notificationBar.notificationSound

     notificationBar.notificationSound("Your sound name", ofType: ".mp3", vibrate: true)
    • By default GLNotificationBar does't play any sound, to play notification sound add this method.

    • This method helps to play notification sound when it is displayed.

    • If mentioned sound file is not found means system default sound will be played.

Author

gokul, gokulece26@gmail.com

Social

code4app

相关源码推荐:

我来说两句
*滑动验证:
所有评论(5)
littleRed 2016-11-25 12:00:28
膜拜大神~
回复
BlueManlove 2016-11-25 12:04:37
code4app确实是个好地方,必须支持~
回复
kengsir 2016-11-25 12:10:57
我是来学习的
回复
AlonMessi 2016-11-25 12:14:57
code4app确实是个好地方,必须支持~
回复
hellokenken 2016-11-25 12:24:24
code4app好的内容真的很多~赞
回复
phoiu 2016-11-25 12:52:52
内容很好,棒棒哒
回复
code4app热心网友 2016-11-28 11:02:59
淡定,淡定,淡定……
回复
code4app热心网友 2016-12-1 14:37:58
楼主用心了,内容非常精彩。
回复
code4app热心网友 2016-12-2 14:32:19
精华内容,楼主V5!
回复
提取码:  下载次数:11 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
353 0 11
代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表