Skip to content

BHToast is a custom UIView written in Swift inspired by Android Toast.

License

Notifications You must be signed in to change notification settings

bbheck/BHToastSwift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BHToast

Swift CI Status Version License Platform

Requirements

  • iOS 8.0+
  • Xcode 7.0+

Installation

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

pod "BHToast"

Usage

Showing a BHToast (only message)

BHToast(view: view, message: "This is an example message.").show()

or

let toast = BHToast(view: view)

toast.message = "This is an example message."
toast.show()

Showing a BHToast (with image)

BHToast(view: view, message: "This is an example message.", imageView: `yourImageView`).show()

or

let toast = BHToast(view: view, message: "This is an example message.")

toast.imageView = `yourImageView`
toast.show()

Showing a BHToast (with options)

import BHToast

let options = BHToastOptions(
    duration: 10.0,
    borderWidth: 0.0,
    cornerRadius: 0.0
)

BHToast(view: view, message: "This is an example message.", options: options).show()

Customizing

BHToastViewTag is used to guarantee only one instance in view. If necessary, change it before first BHToast instance.

You can create a BHToastOptions instance with these properties:

  • The time that BHToast stays in UIView. Default: 5.0
duration: NSTimeInterval
  • The animation time (in seconds). Default: 0.4
animationDuration: NSTimeInterval
  • Toast background color. Default: UIColor.lightGrayColor()
backgroundColor: UIColor
  • Border color. Default: UIColor.darkGrayColor()
borderColor: UIColor
  • Border width. Default: 1.0
borderWidth: CGFloat
  • Corner radius. Default: 5.0
cornerRadius: CGFloat
  • The margin. Default: 8.0
margin: CGFloat
  • The content insets. Default: UIEdgeInsetsMake(8.0, 8.0, 8.0, 8.0)
contentInsets: UIEdgeInsets
  • The min height. Default: 30.0
minHeight: CGFloat
  • The max height. Default: 50.0
maxHeight: CGFloat
  • The message alignment. Default: NSTextAlignment.Center
messageAlignment: NSTextAlignment
  • The message color. Default: UIColor.whiteColor()
messageColor: UIColor
  • The message font. Default: UIFont.systemFontOfSize(14.0)
messageFont: UIFont
  • The view position. Default: BHToastPosition.bottom
position: BHToastPosition
  • The image position (if set). Default: BHToastImagePosition.Left
imagePosition: BHToastImagePosition

All those properties have a default value. Change them to apply the customizations to all new BHToast instances.

Author

Bruno Hecktheuer, bbheck@gmail.com

License

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

About

BHToast is a custom UIView written in Swift inspired by Android Toast.

Resources

License

Stars

Watchers

Forks

Packages

No packages published