DGNotifyView 0.1.5

DGNotifyView 0.1.5

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2018
SwiftSwift Version 3.0.2
SPMSupports SPM

Maintained by Daymein Gregorio.



DGNotifyView is a Swift-based API that allows quick in-app notification views. The notification views can include images, have rounded corners, and best of all there preprogrammed with animations to slide (or spring!) into six different locations. You can even set the notification’s display duration!

Screenshot

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

You need to import UIKit...obviously. ;)

Installation

DGNotifyView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DGNotifyView"

Static Library (manual)

If you prefer to install it manually, copy the files under the DGNotifyView subdirectory into your project. If your application is written in Swift, there’s no need for a bridging header.

Usage

DGNotifyView gives you four options for notifications:

  • DGNotifyView: This is the basic notification view with square edges
  • DGNotifyViewWithImg: This allows you to add an image to the basic notification
  • DGNotifyViewRounded: This is a basic notification view with rounded edges
  • DGNotifyViewRoundedWithImg: Yep. It’s a rounded notification view with image support.

Now with Springy Views! These are the same as above but use a spring animation to come into view:

  • DGNotifyViewSpringy
  • DGNotifyViewSpringyImg
  • DGNotifyViewRoundedSpringy
  • DGNotifyViewRoundedImgSpringy

Initializing

Since DGNotifyView is based on UIView, you’ll need to import UIKit where you are initializing DGNotifyView. Then:

import DGNotifyView

To add a notification, create an instance of your preferred view with the required information and where you want the view to appear from:

let myNotif = DGNotifyView(fromSide: .top, fullWidth: false, 
                           title: “My Title”, message: “Important message”)

Don’t forget to add it to your view when you’re ready to use it:

self.view.addSubview(myNotif)

Customizing

You can change the defalut color of the text and background by calling set(txtColor: UIColor?, bgColor: UIColor?) (setting a parameter to nil leaves it the default color:

myNotif.set(txtColor: UIColor.red, bgColor: UIColor.darkGray)

Animating

Once you have an instance of DGNotifyView, you can call it to slide in with how long it should be displayed. This function ends with a closure in case you want to do something after the animation is completed:

myNotif.displayFor(seconds: 1.0) { (finished) in
            if finished {
               // your code here
            }
        }

To-Do List

There are a few things I’d like to add in the future:

  • [ ] Add ability to set custom colors for text and background
  • [ ] Set custom font
  • [ ] Spring animation option
  • [ ] Swipe out of view

Contributing

If your interested in contributing:

  1. Fork it.
  2. Create your feature branch git checkout -b new-feature
  3. Commit your changes git commit -am ‘Added new-feature
  4. Push to the branch git push origin new-feature
  5. Create a new Pull Request

Author

glowcap, @DaymeinG

License

DGNotifyView is available under the MIT license. See the LICENSE file for more info.