You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
6.0 KiB

5 years ago
  1. # CRToast
  2. [![Build Status](https://travis-ci.org/cruffenach/CRToast.svg?branch=master)](https://travis-ci.org/cruffenach/CRToast)
  3. [![Pod Version](http://img.shields.io/cocoapods/v/CRToast.svg?style=flat)](http://cocoadocs.org/docsets/CRToast)
  4. [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
  5. `CRToast` is a library that allows you to easily create notifications that appear on top of or by pushing out the status bar or navigation bar. `CRToast` was originally based on [CWStatusBarNotification](https://github.com/cezarywojcik/CWStatusBarNotification).
  6. ![demo](screenshots/demo.gif)
  7. ## Requirements
  8. `CRToast` uses ARC and requires iOS 7.0+. Works for iPhone and iPad.
  9. ## Installation
  10. ### CocoaPods
  11. `pod 'CRToast', '~> 0.0.7'`
  12. ### Carthage
  13. `github 'cruffenach/CRToast'`
  14. ### Manual
  15. Add the project or source files to your own project.
  16. ## Usage
  17. Notifications can be created through `CRToastManager`'s `showNotificationWithOptions:completionBlock:` This will queue up a notification with the options specified. You provide options for your notification in a dictionary using the keys in `CRToast.h`
  18. #### Example
  19. This code
  20. ``` objc
  21. NSDictionary *options = @{
  22. kCRToastTextKey : @"Hello World!",
  23. kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
  24. kCRToastBackgroundColorKey : [UIColor redColor],
  25. kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
  26. kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
  27. kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
  28. kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight)
  29. };
  30. [CRToastManager showNotificationWithOptions:options
  31. completionBlock:^{
  32. NSLog(@"Completed");
  33. }];
  34. ```
  35. Generates this
  36. ![](screenshots/red_notification.gif)
  37. ## Customization
  38. `CRToast` is very customizable. Taking a hint from `UIStringDrawing`'s `drawInRect:withAttributes:` book, notifications are created with dictionaries filled with all their options.
  39. ### Customizing Appearance
  40. `CRToast` allows for setting of
  41. - Left aligned image
  42. Title and Subtitle text with:
  43. - Text Color
  44. - Text Font
  45. - Text Alignment
  46. - Text Color
  47. - Text Shadow Color
  48. - Text Shadow Offset
  49. - Text Max Number of Lines
  50. ### Customizing Animation
  51. `CRToast` also allows for animation customization. This includes.
  52. - Animation Type (Linear, Spring or Gravity)
  53. - Animation Physics Coefficients (Spring Damping, Spring Initial Velocity, Gravity Magnitude)
  54. - Presentation Type (Slide over bars or push content out)
  55. - Status visibility (Status bar on top or below)
  56. - Direction (Enter and exit in any direction)
  57. - Enter, Stay on Screen and Exit Timing
  58. ### Touch Interactions
  59. `CRToast` allows for any notification to respond to different types of touch interactions (tap, swipe). Interaction responders can be set as defaults or on a per notification basis.
  60. The types of interactions you can set up to respond to are:
  61. ```Obj-C
  62. CRToastInteractionTypeSwipeUp
  63. CRToastInteractionTypeSwipeLeft
  64. CRToastInteractionTypeSwipeDown
  65. CRToastInteractionTypeSwipeRight
  66. CRToastInteractionTypeTapOnce
  67. CRToastInteractionTypeTapTwice
  68. CRToastInteractionTypeTwoFingerTapOnce
  69. CRToastInteractionTypeTwoFingerTapTwice
  70. ```
  71. There are also wild card interaction types which cover a range of interactions
  72. ```Obj-C
  73. CRToastInteractionTypeSwipe
  74. CRToastInteractionTypeTap
  75. CRToastInteractionTypeAll
  76. ```
  77. Any interaction can be responded to using a `CRToastInteractionResponder`, they can be made with the following constructor
  78. ```
  79. + (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType)interactionType
  80. automaticallyDismiss:(BOOL)automaticallyDismiss
  81. block:(void (^)(CRToastInteractionType interactionType))block;
  82. ```
  83. You can set a collection of `CRToastInteractionResponder`s as the object for the key `kCRToastInteractionRespondersKey` in defaults to have all notifications respond to a certain interaction, or on any given one to have the interaction responders just work for that one notification.
  84. ### Persistent and Programmatically Dismissed Notifications
  85. You can also dismiss the current notification at any time with
  86. ```
  87. + (void)dismissNotification:(BOOL)animated;
  88. ```
  89. You can present notifications that must be dismissed by the user by passing `@(DBL_MAX)` for `kCRToastTimeIntervalKey` and setting up an interaction responder that will dismiss the notification.
  90. ### Setting Defaults
  91. There are sane defaults set for all properties, however you can set a default set of options for your application's notifications using `CRToastManagers`'s `setDefaultOptions:`.
  92. ## License
  93. The MIT License (MIT)
  94. Copyright (c) 2013 Collin Ruffenach
  95. Permission is hereby granted, free of charge, to any person obtaining a copy
  96. of this software and associated documentation files (the "Software"), to deal
  97. in the Software without restriction, including without limitation the rights
  98. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  99. copies of the Software, and to permit persons to whom the Software is
  100. furnished to do so, subject to the following conditions:
  101. The above copyright notice and this permission notice shall be included in
  102. all copies or substantial portions of the Software.
  103. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  104. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  105. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  106. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  107. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  108. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  109. THE SOFTWARE.