/SnackView

Customizable bottom-half alerts.

Primary LanguageSwiftApache License 2.0Apache-2.0

SnackView logo

SnackView

An easy way to present customizable bottom-half alert. SnackView logo

CocoaPods Compatible Platform License Downloads Twitter

What's new in 1.0.8

  • Fixed crash that occurs when SnackView was init with an empty SVItem array.

What's new in 1.0.7

  • Fixed an issue with constraints when keyboard did appear
  • Fixed an issue with constraints with device rotation
  • Added documentation for some methods

Installation with CocoaPods

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).

Podfile

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

Manual installation

If you want to install SnackView manually, just drag SnackView Library folder into your project.

Create your custom SnackView alert

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 alert


SVItems included

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...")

SnackView alert


SVDescriptionItem

SVDescriptionItem(withDescription: "Lorem ipsum dolor sit amet...")

SnackView alert


SVTextFieldItem

SVTextFieldItem(withPlaceholder: "Create Password", 
                  isSecureField: true)

SnackView alert


SVDetailTextItem

SVDetailTextItem(withTitle: "Elit amet", 
                andContent: "Lorem ipsum dolor sit amet...")

SnackView alert


SVButtonItem

SVButtonItem(withTitle: "Continue") { /* Button action here */ }

SnackView alert


SVSwitchItem

SVSwitchItem(withTitle: "Push Notifications", 
            andContent: "Activate to stay up to date...") { (isOn) in  /* Switch action here */ }

SnackView alert


SVLoaderItem

SVLoadingItem(withSize: .large, 
               andText: "Lorem ipsum dolor sit amet...")

SnackView alert Item


Create custom SVItems

You can create custom items subclassing SVItem class.

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)
    }
}

Custom SVItem


Contributing

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