From 5bfadee15587b55f3e1d002ed67f1f1727b755e0 Mon Sep 17 00:00:00 2001 From: Amr Salman Date: Wed, 6 Mar 2019 20:59:51 +0200 Subject: [PATCH 1/4] Changed definition level of IconAlignment enum --- Loaf/Loaf/Loaf.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Loaf/Loaf/Loaf.swift b/Loaf/Loaf/Loaf.swift index b5c8e19..9d0aa8c 100644 --- a/Loaf/Loaf/Loaf.swift +++ b/Loaf/Loaf/Loaf.swift @@ -14,15 +14,6 @@ final public class Loaf { /// Define a custom style for the loaf. public struct Style { - /// Specifies the position of the icon on the loaf. (Default is `.left`) - /// - /// - left: The icon will be on the left of the text - /// - right: The icon will be on the right of the text - public enum IconAlignment { - case left - case right - } - /// The background color of the loaf. let backgroundColor: UIColor @@ -51,6 +42,15 @@ final public class Loaf { } } + /// Specifies the position of the icon on the loaf. (Default is `.left`) + /// + /// - left: The icon will be on the left of the text + /// - right: The icon will be on the right of the text + public enum IconAlignment { + case left + case right + } + /// Defines the loaf's status. (Default is `.info`) /// /// - success: Represents a success message From f03eb69d8eb5d88d56f04f9cd848057fd916bc83 Mon Sep 17 00:00:00 2001 From: Amr Salman Date: Wed, 6 Mar 2019 21:00:36 +0200 Subject: [PATCH 2/4] added IconAlignment property --- Loaf/Loaf/Loaf.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Loaf/Loaf/Loaf.swift b/Loaf/Loaf/Loaf.swift index 9d0aa8c..820605a 100644 --- a/Loaf/Loaf/Loaf.swift +++ b/Loaf/Loaf/Loaf.swift @@ -120,6 +120,7 @@ final public class Loaf { // MARK: - Properties var message: String var state: State + var iconAlignment: IconAlignment var location: Location var duration: Duration = .average var presentingDirection: Direction @@ -130,12 +131,14 @@ final public class Loaf { // MARK: - Public methods public init(_ message: String, state: State = .info, + iconAlignment: IconAlignment = .left, location: Location = .bottom, presentingDirection: Direction = .vertical, dismissingDirection: Direction = .vertical, sender: UIViewController) { self.message = message self.state = state + self.iconAlignment = iconAlignment self.location = location self.presentingDirection = presentingDirection self.dismissingDirection = dismissingDirection From fde98d39405f1d853696accb8715ec649458ee5b Mon Sep 17 00:00:00 2001 From: Amr Salman Date: Wed, 6 Mar 2019 21:01:47 +0200 Subject: [PATCH 3/4] Changed constrainWithIconAlignment() to be determined by IconAlignment property --- Loaf/Loaf/Loaf.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Loaf/Loaf/Loaf.swift b/Loaf/Loaf/Loaf.swift index 820605a..40989f0 100644 --- a/Loaf/Loaf/Loaf.swift +++ b/Loaf/Loaf/Loaf.swift @@ -229,19 +229,19 @@ final class LoafViewController: UIViewController { case .success: imageView.image = Loaf.Icon.success view.backgroundColor = UIColor(hexString: "#2ecc71") - constrainWithIconAlignment(.left) + constrainWithIconAlignment(loaf.iconAlignment) case .warning: imageView.image = Loaf.Icon.warning view.backgroundColor = UIColor(hexString: "##f1c40f") - constrainWithIconAlignment(.left) + constrainWithIconAlignment(loaf.iconAlignment) case .error: imageView.image = Loaf.Icon.error view.backgroundColor = UIColor(hexString: "##e74c3c") - constrainWithIconAlignment(.left) + constrainWithIconAlignment(loaf.iconAlignment) case .info: imageView.image = Loaf.Icon.info view.backgroundColor = UIColor(hexString: "##34495e") - constrainWithIconAlignment(.left) + constrainWithIconAlignment(loaf.iconAlignment) case .custom(style: let style): imageView.image = style.icon view.backgroundColor = style.backgroundColor @@ -269,7 +269,7 @@ final class LoafViewController: UIViewController { } } - private func constrainWithIconAlignment(_ alignment: Loaf.Style.IconAlignment, showsIcon: Bool = true) { + private func constrainWithIconAlignment(_ alignment: Loaf.IconAlignment, showsIcon: Bool = true) { view.addSubview(label) if showsIcon { From 1cab9ea89ed1b5fd02734663735d6c7be20add27 Mon Sep 17 00:00:00 2001 From: Amr Salman Date: Thu, 7 Mar 2019 13:01:47 +0200 Subject: [PATCH 4/4] Removed iconAlignment property from Loaf.Style --- Loaf/Loaf/Loaf.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Loaf/Loaf/Loaf.swift b/Loaf/Loaf/Loaf.swift index 40989f0..25cc599 100644 --- a/Loaf/Loaf/Loaf.swift +++ b/Loaf/Loaf/Loaf.swift @@ -29,16 +29,12 @@ final public class Loaf { /// The icon on the loaf let icon: UIImage? - /// The position of the icon - let iconAlignment: IconAlignment - - public init(backgroundColor: UIColor, textColor: UIColor = .white, tintColor: UIColor = .white, font: UIFont = UIFont.systemFont(ofSize: 14, weight: .medium), icon: UIImage? = Icon.info, iconAlignment: IconAlignment = .left) { + public init(backgroundColor: UIColor, textColor: UIColor = .white, tintColor: UIColor = .white, font: UIFont = UIFont.systemFont(ofSize: 14, weight: .medium), icon: UIImage? = Icon.info) { self.backgroundColor = backgroundColor self.textColor = textColor self.tintColor = tintColor self.font = font self.icon = icon - self.iconAlignment = iconAlignment } } @@ -248,7 +244,7 @@ final class LoafViewController: UIViewController { imageView.tintColor = style.tintColor label.textColor = style.textColor label.font = style.font - constrainWithIconAlignment(style.iconAlignment, showsIcon: imageView.image != nil) + constrainWithIconAlignment(loaf.iconAlignment, showsIcon: imageView.image != nil) } let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))