An easy way to present customizable bottom-half alert.
- Fixed crash that occurs when SnackView was init with an empty SVItem array.
- Fixed an issue with constraints when keyboard did appear
- Fixed an issue with constraints with device rotation
- Added documentation for some methods
CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like SnackView in your projects. You can install it with the following command:
$ gem install cocoapods
CocoaPods 1.0.1+ is required to build SnackView 1+ (along with Swift 3 and Xcode 9).
- Swift 3.x: >= 1.0.1 Download here.
To integrate SnackView into your Xcode project using CocoaPods, specify it in your Podfile
:
use_frameworks!
pod 'SnackView', '~> 1.0.2'
Then, run the following command:
$ pod install
If you want to install SnackView manually, just drag SnackView Library folder into your project.
SnackView includes some default UI elements as Button, Label and other complex UI. The first step is to create an array of SVItem. SVItem is the class of every element that SnackView can include within it.
Here an example of simple SnackView alert:
//SVItem array
let items: Array<SVItem>!
//Define all the view you want to display
let newPassword = SVTextFieldItem(withPlaceholder: "New Password", isSecureField: true)
let repeatPassword = SVTextFieldItem(withPlaceholder: "Repeat Password", isSecureField: true)
let continueButton = SVButtonItem(withTitle: "Continue") {
/* Handle action here */
}
//Populate the SVItem array
items = [newPassword, repeatPassword, continueButton]
//Present the alert on screen.
SnackView(withTitle: "Create password", andCloseButtonTitle: "Cancel", andItems: items).show()
The result will be:
SnackView provides some SVItems ready to use, here below the list of SVItems available:
SVApplicationItem
SVApplicationItem(withIcon: UIImage(named: "AppIcon"),
withTitle: "Ipsum lorem",
andDescription: "Lorem ipsum dolor sit amet...")
SVDescriptionItem
SVDescriptionItem(withDescription: "Lorem ipsum dolor sit amet...")
SVTextFieldItem
SVTextFieldItem(withPlaceholder: "Create Password",
isSecureField: true)
SVDetailTextItem
SVDetailTextItem(withTitle: "Elit amet",
andContent: "Lorem ipsum dolor sit amet...")
SVButtonItem
SVButtonItem(withTitle: "Continue") { /* Button action here */ }
SVSwitchItem
SVSwitchItem(withTitle: "Push Notifications",
andContent: "Activate to stay up to date...") { (isOn) in /* Switch action here */ }
SVLoaderItem
SVLoadingItem(withSize: .large,
andText: "Lorem ipsum dolor sit amet...")
Here below an example.
import UIKit
import SnackView
//Create a subclass of SVItem
class SVCustomItem: SVItem {
//Pass all parameters in init method to customize your SVItem
init(withColor color: UIColor) {
super.init()
//Add an UIView
let customView = UIView()
customView.translatesAutoresizingMaskIntoConstraints = false
customView.backgroundColor = color
self.addSubview(customView)
//Add UIView contraints
let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[customView(70)]-|", options: [], metrics: nil, views: ["customView":customView])
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|-[customView]-|", options: [], metrics: nil, views: ["customView": customView])
self.addConstraints(vConstraints + hConstraints)
}
required public convenience init?(coder aDecoder: NSCoder) {
self.init(coder: aDecoder)
}
}
If you want to contribute to make SnackView a better framework, submit a pull request.
Please consider to open an issue for the following reasons:
- If you have questions or if you need help using SnackView
- If you found a bug
- If you have some feature request