Skip to content

cs-joao-souza/JPAlertController

Repository files navigation

JPAlertController

JPAlertController is Swift alert all customizable. It's usage look like UIAlertController usage.
Using JPAlertController you can customize every text in your alert just sending some options in the constructor.

Screenshots

ScreenShot ScreenShot

Requirements

  • iOS 9.0+
  • Xcode 8.1+
  • Swift 3.0+

Usage

It's usage is very similar to UIAlertController. The difference is that is possible to pass options to configure your text as you want. These options need to be NSAttributedString attributes. So is possible to use:

  • NSFontAttributeName
  • NSParagraphStyleAttributeName
  • NSForegroundColorAttributeName
  • NSBackgroundColorAttributeName
  • NSLigatureAttributeName
  • NSKernAttributeName
  • NSStrikethroughStyleAttributeName
  • NSUnderlineStyleAttributeName
  • NSStrokeColorAttributeName
  • NSStrokeWidthAttributeName
  • NSShadowAttributeName
  • NSTextEffectAttributeName
  • NSAttachmentAttributeName
  • NSLinkAttributeName
  • NSBaselineOffsetAttributeName
  • NSBaselineOffsetAttributeName
  • ...
  • and so on.
let titleOptions = [ NSFontAttributeName: UIFont(name: "Chalkduster", size: 18.0)!, NSForegroundColorAttributeName: UIColor.blue ]
    
let messageOptions = [ NSFontAttributeName: UIFont(name: "Chalkduster", size: 14.0)!, NSForegroundColorAttributeName: UIColor.red ]
    
let alert = JPAlertController(title: "Alert", message: "This is a customizable Alert", titleOptions: titleOptions, messageOptions: messageOptions)
    
    
let okAction = JPAlertAction(title: "OK", titleOptions: titleOptions) { action in
    print("OK action")
}
    
alert.addAction(action: okAction)
    
    
let cancelOptions = [ NSFontAttributeName: UIFont(name: "Chalkduster", size: 14.0)!, NSForegroundColorAttributeName: UIColor.red ]
    
let cancelAction = JPAlertAction(title: "Cancel", titleOptions: cancelOptions) { action in
  print("Cancel action")
}
    
alert.addAction(action: cancelAction)
    
self.present(alert, animated: true, completion: nil)

Installation

Cocoapods

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

pod 'JPAlertController'

Manual

Just copy and paste the files inside source code folder into your project.

Todo

  • Add separators
  • Let it be able to customize the background
  • Let it be able to customize the viewController's background

License

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