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.

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. TSMessages
  2. ==========
  3. This library provides an easy to use class to show little notification views on the top of the screen. (à la Tweetbot).
  4. [![Twitter: @KauseFx](https://img.shields.io/badge/contact-@KrauseFx-blue.svg?style=flat)](https://twitter.com/KrauseFx)
  5. [![Version](https://img.shields.io/cocoapods/v/TSMessages.svg?style=flat)](http://cocoadocs.org/docsets/TSMessages)
  6. [![License](https://img.shields.io/cocoapods/l/TSMessages.svg?style=flat)](http://cocoadocs.org/docsets/TSMessages)
  7. [![Platform](https://img.shields.io/cocoapods/p/TSMessages.svg?style=flat)](http://cocoadocs.org/docsets/TSMessages)
  8. The notification moves from the top of the screen underneath the navigation bar and stays there for a few seconds, depending on the length of the displayed text. To dismiss a notification before the time runs out, the user can swipe it to the top or just tap it.
  9. There are 4 different types already set up for you: Success, Error, Warning, Message (take a look at the screenshots)
  10. It is very easy to add new notification types with a different design. Add the new type to the notificationType enum, add the needed design properties to the configuration file and set the name of the theme (used in the config file and images) in TSMessagesView.m inside the switch case.
  11. **Take a look at the Example project to see how to use this library.** You have to open the workspace, not the project file, since the Example project uses cocoapods.
  12. Follow the developer on Twitter: [KrauseFx](http://twitter.com/KrauseFx) (Felix Krause)
  13. # Installation
  14. ## From CocoaPods
  15. TSMessages is available through [CocoaPods](http://cocoapods.org). To install
  16. it, simply add the following line to your Podfile:
  17. pod "TSMessages"
  18. ## Manually
  19. Copy the source files TSMessageView and TSMessage into your project. Also copy the TSMessagesDesignDefault.json.
  20. # Usage
  21. To show notifications use the following code:
  22. ```objective-c
  23. [TSMessage showNotificationWithTitle:@"Your Title"
  24. subtitle:@"A description"
  25. type:TSMessageNotificationTypeError];
  26. // Add a button inside the message
  27. [TSMessage showNotificationInViewController:self
  28. title:@"Update available"
  29. subtitle:@"Please update the app"
  30. image:nil
  31. type:TSMessageNotificationTypeMessage
  32. duration:TSMessageNotificationDurationAutomatic
  33. callback:nil
  34. buttonTitle:@"Update"
  35. buttonCallback:^{
  36. NSlog(@"User tapped the button");
  37. }
  38. atPosition:TSMessageNotificationPositionTop
  39. canBeDismissedByUser:YES];
  40. // Use a custom design file
  41. [TSMessage addCustomDesignFromFileWithName:@"AlternativeDesign.json"];
  42. ```
  43. You can define a default view controller in which the notifications should be displayed:
  44. ```objective-c
  45. [TSMessage setDefaultViewController:myNavController];
  46. ```
  47. You can define a default view controller in which the notifications should be displayed:
  48. ```objective-c
  49. [TSMessage setDelegate:self];
  50. ...
  51. - (CGFloat)messageLocationOfMessageView:(TSMessageView *)messageView
  52. {
  53. return messageView.viewController...; // any calculation here
  54. }
  55. ```
  56. You can customize a message view, right before it's displayed, like setting an alpha value, or adding a custom subview
  57. ```objective-c
  58. [TSMessage setDelegate:self];
  59. ...
  60. - (void)customizeMessageView:(TSMessageView *)messageView
  61. {
  62. messageView.alpha = 0.4;
  63. [messageView addSubview:...];
  64. }
  65. ```
  66. The following properties can be set when creating a new notification:
  67. * **viewController**: The view controller to show the notification in. This might be the navigation controller.
  68. * **title**: The title of the notification view
  69. * **subtitle**: The text that is displayed underneath the title (optional)
  70. * **image**: A custom icon image that is used instead of the default one (optional)
  71. * **type**: The notification type (Message, Warning, Error, Success)
  72. * **duration**: The duration the notification should be displayed
  73. * **callback**: The block that should be executed, when the user dismissed the message by tapping on it or swiping it to the top.
  74. Except the title and the notification type, all of the listed values are optional
  75. If you don't want a detailed description (the text underneath the title) you don't need to set one. The notification will automatically resize itself properly.
  76. ## Screenshots
  77. **iOS 7 Design**
  78. ![iOS 7 Error](http://www.toursprung.com/wp-content/uploads/2013/09/error_ios7.png)
  79. ![iOS 7 Message](http://www.toursprung.com/wp-content/uploads/2013/09/warning_ios7.png)
  80. **iOS 6 Design**
  81. ![Warning](http://www.toursprung.com/wp-content/uploads/2013/04/iNotificationWarning.png)
  82. ![Success](http://www.toursprung.com/wp-content/uploads/2013/04/iNotificationSuccess.png)
  83. ![Error](http://www.toursprung.com/wp-content/uploads/2013/04/iNotificationError.png)
  84. ![Message](http://www.toursprung.com/wp-content/uploads/2013/04/iNotificationMessage.png)
  85. # License
  86. TSMessages is available under the MIT license. See the LICENSE file for more information.
  87. # Recent Changes
  88. Can be found in the [releases section](https://github.com/toursprung/TSMessages/releases) of this repo.