Giter Site home page Giter Site logo

JSSAlertView

Swift5 Swift4.2 Swift4 Swift3 Swift2 Build Status Carthage compatible Version License Platform

SWIFT Versions!

For swift5 use:

pod 'JSSAlertView'

For swift4.2 use:

pod 'JSSAlertView', '~> 4.2.0'

For swift4 use:

pod 'JSSAlertView', '~> 4.0.0'

For swift3 use:

pod 'JSSAlertView', '~> 3.0.4'

For swift2 use:

pod 'JSSAlertView', '~> 1.1.5'

A custom "modal" alert view for iOS 7+ written in Swift, with a couple basic themes and support for custom icons and fonts. Inspired by and modeled after vikmeup's SCLAlertView.

BackgroundImage

Try out (Over Cocoapods)

pod try JSSAlertView

Try out (Cloning repo)

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

Installation

Cocoapods

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

pod 'JSSAlertView'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. A minimum version of 0.17 is required.

To install, simply add the following lines to your Cartfile:

github "JSSAlertView/JSSAlertView"

Usage

Make sure you imported JSSAlertView with following

import JSSAlertView

The most minimal alert just has a title.

JSSAlertView().show(
  self, // the parent view controller of the alert
  title: "I'm an alert" // the alert's title
)

The delayed Alert

JSSAlertView().show(
  self, // the parent view controller of the alert
  title: "I'm an alert", // the alert's title
  delay: 3 // time in secs
)

You'll always want to first pass a reference to the view controller that you wish to add the overlay and alert subviews to.

Besides the default show() method you can call any of four alert themes: info(), success(), warning(), and danger().

JSSAlertView().success(
  self,
  title: "Great success",
  text: "This is the built-in .success style"
)

You can customize button text, add a custom icon and customize the alert color.

var customIcon:UIImage! // your custom icon UIImage
var customColor:UIColor! // base color for the alert
JSSAlertView().show(
  self,
  title: "Another alert",
  text: "An alert with more customizations.",
  buttonText: "Right on",
  color: customColor,
  iconImage: customIcon)

You can also decide not to show any buttons with argument noButtons: true by doing so, JSSAlerView will close on tap and sends close callback.

JSSAlertView().show(
	self,
	title: "Custom color",
	text: "All of the cool kids have purple alerts these days",
	buttonText: "Whoa",
	color: UIColorFromHex(0x9b59b6, alpha: 1))

You can also provide a callback function to run after the alert is dismissed, specify custom fonts and change the alert's text color from dark to light.

func myCallback() {
  // this'll run after the alert is dismissed
}
var alertview = JSSAlertView().show(self,
  title: "Yet another alert",
  text: "Callbacks, fonts and text colors"
)
alertview.addAction(myCallback) // Method to run after dismissal
alertview.setTitleFont("ClearSans-Bold") // Title font
alertview.setTextFont("ClearSans") // Alert body text font
alertview.setButtonFont("ClearSans-Light") // Button text font
alertview.setTextTheme(.Light) // can be .Light or .Dark

Finally, two-button alerts with a cancel button on the left are possible by passing in some cancelButtonText. The button on the left side of the alert will reflect that text and simply dismiss the alert when tapped, with an optional cancel callback. The right-hand button will also dismiss the alert as usual, with the appropriate close callback if present.

func myCancelCallback() {
  // this'll run if cancel is pressed after the alert is dismissed
}
var alertview = JSSAlertView().show(
  self,
  title: "I'm an alert",
  text: "An alert with two buttons. Dismiss by tapping the left, and do something else by tapping the right.",
  buttonText: "OK",
  cancelButtonText: "Cancel" // This tells JSSAlertView to create a two-button alert
)
alertview.addCancelAction(myCancelCallback)

See the included example project for more!

Author

The initial author is Jay Stakelon http://stakelon.com

Current maintainer is Tomas Sykora, jr. http://syky.cz

License

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

jssalertview's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.