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

Fixes to #18 and #36 #37

Open
wants to merge 2 commits into
base: main
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
16 changes: 12 additions & 4 deletions Sources/Toast/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ public class Toast {
public static func text(
_ title: NSAttributedString,
subtitle: NSAttributedString? = nil,
titleNumberOfLines: Int = 0,
subtitleNumberOfLines: Int = 0,
config: ToastConfiguration = ToastConfiguration()
) -> Toast {
let view = AppleToastView(child: TextToastView(title, subtitle: subtitle))
let view = AppleToastView(child: TextToastView(title, subtitle: subtitle, titleNumberOfLines: titleNumberOfLines, subtitleNumberOfLines: subtitleNumberOfLines))
return self.init(view: view, config: config)
}

Expand All @@ -82,9 +84,11 @@ public class Toast {
public static func text(
_ title: String,
subtitle: String? = nil,
titleNumberOfLines: Int = 0,
subtitleNumberOfLines: Int = 0,
config: ToastConfiguration = ToastConfiguration()
) -> Toast {
let view = AppleToastView(child: TextToastView(title, subtitle: subtitle))
let view = AppleToastView(child: TextToastView(title, subtitle: subtitle, titleNumberOfLines: titleNumberOfLines, subtitleNumberOfLines: subtitleNumberOfLines))
return self.init(view: view, config: config)
}

Expand All @@ -101,10 +105,12 @@ public class Toast {
imageTint: UIColor? = defaultImageTint,
title: NSAttributedString,
subtitle: NSAttributedString? = nil,
titleNumberOfLines: Int = 0,
subtitleNumberOfLines: Int = 0,
config: ToastConfiguration = ToastConfiguration()
) -> Toast {
let view = AppleToastView(
child: IconAppleToastView(image: image, imageTint: imageTint, title: title, subtitle: subtitle)
child: IconAppleToastView(image: image, imageTint: imageTint, title: title, subtitle: subtitle, titleNumberOfLines: titleNumberOfLines, subtitleNumberOfLines: subtitleNumberOfLines)
)
return self.init(view: view, config: config)
}
Expand All @@ -122,10 +128,12 @@ public class Toast {
imageTint: UIColor? = defaultImageTint,
title: String,
subtitle: String? = nil,
titleNumberOfLines: Int = 0,
subtitleNumberOfLines: Int = 0,
config: ToastConfiguration = ToastConfiguration()
) -> Toast {
let view = AppleToastView(
child: IconAppleToastView(image: image, imageTint: imageTint, title: title, subtitle: subtitle)
child: IconAppleToastView(image: image, imageTint: imageTint, title: title, subtitle: subtitle, titleNumberOfLines: titleNumberOfLines, subtitleNumberOfLines: subtitleNumberOfLines)
)
return self.init(view: view, config: config)
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/Toast/ToastViews/AppleToastView/AppleToastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AppleToastView : UIView, ToastView {

private let child: UIView

private weak var toast: Toast?
private var toast: Toast?

public init(
child: UIView,
Expand All @@ -36,6 +36,11 @@ public class AppleToastView : UIView, ToastView {
addSubview(child)
}

public override func removeFromSuperview() {
super.removeFromSuperview()
self.toast = nil
}

public func createView(for toast: Toast) {
self.toast = toast
guard let superview = superview else { return }
Expand Down
17 changes: 15 additions & 2 deletions Sources/Toast/ToastViews/AppleToastView/IconAppleToastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ public class IconAppleToastView : UIStackView {
image: UIImage,
imageTint: UIColor? = defaultImageTint,
title: NSAttributedString,
subtitle: NSAttributedString? = nil
subtitle: NSAttributedString? = nil,
titleNumberOfLines: Int = 0,
subtitleNumberOfLines: Int = 0
) {
super.init(frame: CGRect.zero)
commonInit()

self.titleLabel.attributedText = title
self.titleLabel.numberOfLines = titleNumberOfLines
self.vStack.addArrangedSubview(self.titleLabel)

if let subtitle = subtitle {
self.subtitleLabel.attributedText = subtitle
self.subtitleLabel.numberOfLines = subtitleNumberOfLines
self.vStack.addArrangedSubview(self.subtitleLabel)
}

Expand All @@ -71,18 +75,27 @@ public class IconAppleToastView : UIStackView {
addArrangedSubview(self.vStack)
}

public init(image: UIImage, imageTint: UIColor? = defaultImageTint, title: String, subtitle: String? = nil) {
public init(
image: UIImage,
imageTint: UIColor? = defaultImageTint,
title: String,
subtitle: String? = nil,
titleNumberOfLines: Int = 0,
subtitleNumberOfLines: Int = 0
) {
super.init(frame: CGRect.zero)
commonInit()

self.titleLabel.text = title
self.titleLabel.numberOfLines = titleNumberOfLines
self.titleLabel.font = .systemFont(ofSize: 14, weight: .bold)
self.vStack.addArrangedSubview(self.titleLabel)

if let subtitle = subtitle {
self.subtitleLabel.textColor = .systemGray
self.subtitleLabel.text = subtitle
self.subtitleLabel.font = .systemFont(ofSize: 12, weight: .bold)
self.subtitleLabel.numberOfLines = subtitleNumberOfLines
self.vStack.addArrangedSubview(self.subtitleLabel)
}

Expand Down
18 changes: 16 additions & 2 deletions Sources/Toast/ToastViews/AppleToastView/TextAppleToastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,45 @@ public class TextToastView : UIStackView {
UILabel()
}()

public init(_ title: NSAttributedString, subtitle: NSAttributedString? = nil) {
public init(
_ title: NSAttributedString,
subtitle: NSAttributedString? = nil,
titleNumberOfLines: Int = 0,
subtitleNumberOfLines: Int = 0
) {
super.init(frame: CGRect.zero)
commonInit()

self.titleLabel.attributedText = title
self.titleLabel.numberOfLines = titleNumberOfLines
addArrangedSubview(self.titleLabel)

if let subtitle = subtitle {
self.subtitleLabel.attributedText = subtitle
self.subtitleLabel.numberOfLines = subtitleNumberOfLines
addArrangedSubview(subtitleLabel)
}
}

public init(_ title: String, subtitle: String? = nil) {
public init(
_ title: String,
subtitle: String? = nil,
titleNumberOfLines: Int = 0,
subtitleNumberOfLines: Int = 0
) {
super.init(frame: CGRect.zero)
commonInit()

self.titleLabel.text = title
self.titleLabel.numberOfLines = titleNumberOfLines
self.titleLabel.font = .systemFont(ofSize: 14, weight: .bold)
addArrangedSubview(self.titleLabel)

if let subtitle = subtitle {
self.subtitleLabel.textColor = .systemGray
self.subtitleLabel.text = subtitle
self.subtitleLabel.font = .systemFont(ofSize: 12, weight: .bold)
self.subtitleLabel.numberOfLines = subtitleNumberOfLines
addArrangedSubview(self.subtitleLabel)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ToastViewSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
#

spec.name = "ToastViewSwift"
spec.version = ENV['LIB_VERSION'] || "1.0"
spec.version = ENV['LIB_VERSION'] || "1.0.1"
spec.summary = "A Swift Toast view - iOS 14 style and newer - built with UIKit. 🍞"

# This description is used to generate tags and improve search results.
Expand Down