TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2016 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Sai Prasanna.
This is port of TSMessages library to Swift. The iOS6 design option is dropped.
This library provides an easy to use class to show little notification views on the top of the screen.
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.
There are 4 different types already set up for you: Success, Error, Warning, Message (take a look at the screenshots)
Take a look at the Example project to see how to use this library.
v0.2.0 -> Swift 2.2
v0.3.0 -> Swift 3.0
Copy the source files and asset files from SWMessages directory to your project. It is the only way to make this work in iOS 7.
iOS7+
To show notifications use the following code:
SWMessage.sharedInstance.showNotificationWithTitle(
"Title",
subtitle: "Subtitle",
type: .success
)
// Add a button inside the message
SWMessage.sharedInstance.showNotificationInViewController (
self,
title: "Update available",
subtitle: "Please update our app. We added AI to replace you",
image: nil,
type: .success,
duration: .automatic,
callback: nil,
buttonTitle: "Update",
buttonCallback: {
SWMessage.showNotificationWithTitle("Thanks for updating", type: .success)
},
atPosition: .top,
canBeDismissedByUser: true
)
You can define a default view controller in which the notifications should be displayed:
```swift
SWMessage.sharedInstance.defaultViewController = myNavController
You can set custom offset to position message.
SWMessage.sharedInstance.offsetHeightForMessage = 10.0
You can customize a message view, right before it’s displayed, like setting an alpha value, or adding a custom subview
SWMessage.customizeMessageView = { (messageView) in
messageView.alpha = ..
messageView.addSubView(someView)
}
You can customize message view for default message types by setting the styleForMessageType callback which takes the type of message as parameter and returns a SWMessageView.Style struct object.
SWMessageView.styleForMessageType = { (type)
....
return SWMessageView.Style(...)
}
The following properties can be set when creating a new notification:
Except the title and the notification type, all of the listed values are optional
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.
SWMessages is available under the MIT license. See the LICENSE file for more information.