sna

SnackView

Customizable bottom-half alerts.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

285

Maintenance

Last Commit

4mos ago

Contributors

2

Package

Dependencies

0

License

MIT

Categories

Readme

SnackView logo

SnackView

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

CocoaPods Compatible Carthage Compatible Platform License Twitter

Maintainability Test Coverage

Roadmap

SnackView RoadMap

What's new

What's new in 1.1.0

  • Added support for Dark mode.
  • Added item SVSliderItem.
  • Removed deprecated methods and files.

What's new in 1.0.9

  • New SnackViewDataSource protocol with which create your SnackView.
  • New SVImageViewItem class with which display images.
  • Compatible with the new UIWindowSceneDelegate system.

Installation

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

  • 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.1.0'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate SnackView into your Xcode project using Carthage, specify it in your Cartfile:

github "lucacasula91/SnackView"

Manual installation

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

Usage

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:

class MyCustomClass: UIViewController {

    override func viewDidLoad() {  }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        // Present the SnackView
        let dataSource = self
        SnackView(with: dataSource).show()
    }
}

// MARK: - SnackViewDataSource Section
extension MyCustomClass: SnackViewDataSource {

    func titleFor(snackView: SnackView) -> String {
        return "What's New"
    }

    func cancelTitleFor(snackView: SnackView) -> String? {
        return "Dismiss"
    }

    func itemsFor(snackView: SnackView) -> [SVItem] {
        let descriptionItem = SVDescriptionItem(withDescription: "In this last release of SnackView we...")
        let imageItem = SVImageViewItem(withImage: UIImage(named: "hat_is_new")!,
                                        andContentMode: .scaleAspectFill)

        return [descriptionItem, imageItem]
    }
}


Deprecated methods

With SnackView 1.0.9 the current method are now deprecated:

  • init(withTitleOptions: andItems:)
  • init(withTitle: andCloseButtonTitle: andItems:)

SnackViewDataSource contains all you need to handle title, cancel button title and items to display. For more info please see the SnackViewDataSource protocol documentation code.

  • func insert(item: atIndex:)
  • func remove(item:)
  • func removeItemAt(index:)
  • func updateWith(items:)

Please start using the new SnackViewDataSource instead, all the above operations can be performed simply by changing the return content in the func itemsFor(snackView:) method of SnackViewDataSource and call the reloadData() function to perform an update.


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


SVImaveViewItem

SVImageViewItem(with: UIImage(named: "hat_is_new")!,
                              andContentMode: .scaleAspectFill)

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100