Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image tint color added #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ extension ViewController {
case 3: cell.textLabel?.text = "Make toast with an image"
case 4: cell.textLabel?.text = "Make toast with a title, image, and completion closure"
case 5: cell.textLabel?.text = "Make toast with a custom style"
case 6: cell.textLabel?.text = "Show a custom view as toast"
case 7: cell.textLabel?.text = "Show an image as toast at point\n(110, 110)"
case 8: cell.textLabel?.text = showingActivity ? "Hide toast activity" : "Show toast activity"
case 9: cell.textLabel?.text = "Hide toast"
case 10: cell.textLabel?.text = "Hide all toasts"
case 6: cell.textLabel?.text = "Make toast with a custom style and image"
case 7: cell.textLabel?.text = "Show a custom view as toast"
case 8: cell.textLabel?.text = "Show an image as toast at point\n(110, 110)"
case 9: cell.textLabel?.text = showingActivity ? "Hide toast activity" : "Show toast activity"
case 10: cell.textLabel?.text = "Hide toast"
case 11: cell.textLabel?.text = "Hide all toasts"
default: cell.textLabel?.text = nil
}

Expand Down Expand Up @@ -193,16 +194,25 @@ extension ViewController {
style.backgroundColor = UIColor.yellow
self.navigationController?.view.makeToast("This is a piece of toast with a custom style", duration: 3.0, position: .bottom, style: style)
case 6:
// Make toast with a custom style and image
var style = ToastStyle()
style.messageFont = UIFont(name: "Zapfino", size: 14.0)!
style.messageColor = UIColor.red
style.messageAlignment = .center
style.backgroundColor = UIColor.yellow
style.imageTint = .red
self.navigationController?.view.makeToast("This is a piece of toast with a custom style", duration: 3.0, position: .bottom, image: UIImage(named: "toast.png"), style: style)
case 7:
// Show a custom view as toast
let customView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 80.0, height: 400.0))
customView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin]
customView.backgroundColor = .lightBlue
self.navigationController?.view.showToast(customView, duration: 2.0, position: .center)
case 7:
case 8:
// Show an image view as toast, on center at point (110,110)
let toastView = UIImageView(image: UIImage(named: "toast.png"))
self.navigationController?.view.showToast(toastView, duration: 2.0, point: CGPoint(x: 110.0, y: 110.0))
case 8:
case 9:
// Make toast activity
if !showingActivity {
self.navigationController?.view.makeToastActivity(.center)
Expand All @@ -213,10 +223,10 @@ extension ViewController {
showingActivity.toggle()

tableView.reloadData()
case 9:
case 10:
// Hide toast
self.navigationController?.view.hideToast()
case 10:
case 11:
// Hide all toasts
self.navigationController?.view.hideAllToasts()
default:
Expand Down
10 changes: 9 additions & 1 deletion Toast/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,12 @@ public extension UIView {
}

if let image = image {
imageView = UIImageView(image: image)
imageView = UIImageView(image: style.imageTint == .clear ? image : image.withRenderingMode(.alwaysTemplate))
imageView?.contentMode = .scaleAspectFit
imageView?.frame = CGRect(x: style.horizontalPadding, y: style.verticalPadding, width: style.imageSize.width, height: style.imageSize.height)
if style.imageTint != .clear {
imageView?.tintColor = style.imageTint
}
}

var imageRect = CGRect.zero
Expand Down Expand Up @@ -682,6 +685,11 @@ public struct ToastStyle {
*/
public var imageSize = CGSize(width: 80.0, height: 80.0)

/**
The image tint color. If not .clear then image will be rendered as template and tint will be applied. Default is .clear.
*/
public var imageTint = UIColor.clear

/**
The size of the toast activity view when `makeToastActivity(position:)` is called.
Default is 100 x 100.
Expand Down