Skip to content

A custom alert view for iOS 7 and 8 written in Swift.

License

Notifications You must be signed in to change notification settings

itsmeichigo/JSSAlertView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSSAlertView

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

BackgroundImage

How to use

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
)

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)

And 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

See the included example project for more!

How to install

Just add the JSSAlertView.swift file to your Xcode project. Maybe one day I'll make it available through CocoaPods.

About

A custom alert view for iOS 7 and 8 written in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 91.4%
  • Ruby 8.6%