From cb3c7a01d88ee61b5d066abe9c9c5f954f32cb09 Mon Sep 17 00:00:00 2001 From: daniel-dumortier Date: Fri, 22 Jul 2022 17:35:08 +0200 Subject: [PATCH 1/5] feat(button) : add icon alone button type, and refactor icon management --- .../Button/Cell/ButtonTableViewCell.swift | 25 ++- .../Button/Cell/ButtonTableViewCell.xib | 34 +++- .../VitaminUIKit/Components/Button/README.md | 36 ++++ .../Button/VitaminButton+Deprecated.swift | 25 +++ .../Components/Button/VitaminButton.swift | 171 ++++++++++++++---- 5 files changed, 245 insertions(+), 46 deletions(-) create mode 100644 Sources/VitaminUIKit/Components/Button/VitaminButton+Deprecated.swift diff --git a/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.swift b/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.swift index 9cee8f4e..316ff338 100644 --- a/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.swift +++ b/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.swift @@ -19,21 +19,36 @@ final class ButtonTableViewCell: UITableViewCell { largeButton.size = .large } } + @IBOutlet weak var mediumIconAloneButton: VitaminButton! { + didSet { + mediumIconAloneButton.size = .medium + } + } + + @IBOutlet weak var largeIconAloneButton: VitaminButton! { + didSet { + largeIconAloneButton.size = .large + } + } func update(for style: VitaminButton.Style, isEnabled: Bool) { mediumButton.style = style largeButton.style = style + mediumIconAloneButton.style = style + largeIconAloneButton.style = style mediumButton.setTitle("\(style)", for: .normal) largeButton.setTitle("\(style)", for: .normal) - mediumButton.setLeadingImage(Vitamix.Line.Logos.apple.image, for: .normal, renderingMode: .alwaysTemplate) - largeButton.setTrailingImage( - Vitamix.Line.System.arrowRightS.image, - for: .normal, - renderingMode: .alwaysTemplate) + + mediumButton.setIconType(.trailing(image: Vitamix.Line.Logos.apple.image, renderingMode: .alwaysTemplate), for: .normal) + largeButton.setIconType(.leading(image: Vitamix.Line.System.arrowRightS.image, renderingMode: .alwaysTemplate), for: .normal) + mediumIconAloneButton.setIconType(.alone(image: Vitamix.Line.Logos.apple.image, renderingMode: .alwaysTemplate), for: .normal) + largeIconAloneButton.setIconType(.alone(image: Vitamix.Line.System.arrowRightS.image, renderingMode: .alwaysTemplate), for: .normal) mediumButton.isEnabled = isEnabled largeButton.isEnabled = isEnabled + mediumIconAloneButton.isEnabled = isEnabled + largeIconAloneButton.isEnabled = isEnabled contentView.backgroundColor = style.needsReversedBackground ? VitaminColor.Core.Background.brandPrimary : diff --git a/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.xib b/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.xib index 6e4d0e95..ed22e0c8 100644 --- a/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.xib +++ b/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.xib @@ -1,9 +1,9 @@ - + - + @@ -18,21 +18,41 @@ - + - + + + + + + + @@ -45,7 +65,9 @@ + + diff --git a/Sources/VitaminUIKit/Components/Button/README.md b/Sources/VitaminUIKit/Components/Button/README.md index f49d596b..09aa7743 100644 --- a/Sources/VitaminUIKit/Components/Button/README.md +++ b/Sources/VitaminUIKit/Components/Button/README.md @@ -22,3 +22,39 @@ A good example of that would be to make your button stretched to fit its parent' Note: `VitaminButton` styles its title as `TextStyle.xxxbutton`, so make sure you setup the Roboto fonts properly. If you create your button through Storyboard or Xib, do not forget to set its type to `Custom` (instead of `System`, which is the default value). If not set to `Custom`, `VitaminButton` may act oddly in some circumstances. + +### Icon management +You can put an icon from Vitamin icons library in your button, or also have a square button with only one icon. + +To achieve this, `VitaminButton` provides you with a `setIconType(:for:)` method. +You can have different icons, or even different icon types per state. + +`IconType` has four cases : +- `.leading` : icon will be put before your button label +- `.trailing` : icon will be put after your button label +- `.alone` : button will be squared, an icon will be centered, and no button label will be displayed +- `.none` : no icon will be displayed in your button + +For `.leading`, `.trailing` and `.alone`, you must provide : +- an `UIImage` from Vitamin icons library (but will work with any UIImage) +- an optional `UIImage.RenderingMode` : if you provide one, image will be resized using this rendering mode, if not, image will be used as is (with unexpected behaviour if your image has a wrong size) + +If you do not specify specific icon type for a specific state, the one for .normal state will be chosen. +And by default, the icon type for .normal state is .none + +Note: squareness of VitaminButton with `.alone` is handled through intrisicSize, it is not guaranteed if you apply constants that could impact width and height of button. + +```swift +import Vitamin + +// This button will have a white background with a dark border +// and an apple logo before text (in every state, since only .normal state has been set) +let button = VitaminButton(style: .secondary) +button.setIconType(.trailing(image: Vitamix.Line.Logos.apple.image, renderingMode: .alwaysTemplate), for: .normal) + +// This button will be square, have a blue background and a white icon centered +// icon will be an Apple logo in normal state, and an Android logo in .highlighted state +let button2 = VitaminButton(style: .primary) +button2.setIconType(.trailing(image: Vitamix.Line.Logos.apple.image, renderingMode: .alwaysTemplate), for: .normal) +button2.setIconType(.trailing(image: Vitamix.Line.Logos.android.image, renderingMode: .alwaysTemplate), for: .highlighted) +``` diff --git a/Sources/VitaminUIKit/Components/Button/VitaminButton+Deprecated.swift b/Sources/VitaminUIKit/Components/Button/VitaminButton+Deprecated.swift new file mode 100644 index 00000000..e160950d --- /dev/null +++ b/Sources/VitaminUIKit/Components/Button/VitaminButton+Deprecated.swift @@ -0,0 +1,25 @@ +// +// Vitamin iOS +// Apache License 2.0 +// + +import UIKit + +extension VitaminButton { + @available(*, deprecated, message: "Use setIconType(:for:) instead") + public func setLeadingImage(_ image: UIImage, for state: UIControl.State) { + setIconType(.leading(image: image, renderingMode: nil), for: state) + } + @available(*, deprecated, message: "Use setIconType(:for:) instead") + public func setTrailingImage(_ image: UIImage, for state: UIControl.State) { + setIconType(.trailing(image: image, renderingMode: nil), for: state) + } + @available(*, deprecated, message: "Use setIconType(:for:) instead") + public func setLeadingImage(_ image: UIImage, for state: UIControl.State, renderingMode: UIImage.RenderingMode) { + setIconType(.leading(image: image, renderingMode: renderingMode), for: state) + } + @available(*, deprecated, message: "Use setIconType(:for:) instead") + public func setTrailingImage(_ image: UIImage, for state: UIControl.State, renderingMode: UIImage.RenderingMode) { + setIconType(.trailing(image: image, renderingMode: renderingMode), for: state) + } +} diff --git a/Sources/VitaminUIKit/Components/Button/VitaminButton.swift b/Sources/VitaminUIKit/Components/Button/VitaminButton.swift index b2d132a9..6b5d01f5 100644 --- a/Sources/VitaminUIKit/Components/Button/VitaminButton.swift +++ b/Sources/VitaminUIKit/Components/Button/VitaminButton.swift @@ -33,16 +33,29 @@ public class VitaminButton: UIButton { applyNewTextStyle() } } + + public enum IconType { + case trailing(image: UIImage, renderingMode: UIImage.RenderingMode?) + case leading(image: UIImage, renderingMode: UIImage.RenderingMode?) + case alone(image: UIImage, renderingMode: UIImage.RenderingMode?) + case none + } + + private var iconTypes: [UIControl.State:IconType] = [.normal: .none] public override var isEnabled: Bool { didSet { updateOpacity() + updateSemantic() + updateImageInsets() } } public override var isHighlighted: Bool { didSet { updateBorder() + updateSemantic() + updateImageInsets() } } @@ -51,6 +64,7 @@ public class VitaminButton: UIButton { super.init(frame: .zero) applyNewStyle() applyNewTextStyle() + } public required init?(coder: NSCoder) { @@ -67,45 +81,15 @@ public class VitaminButton: UIButton { public override var intrinsicContentSize: CGSize { let baseSize = super.intrinsicContentSize return CGSize( - width: 2 * size.horizontalInset + baseSize.width, - height: 2 * size.verticalInset + baseSize.height + width: 2 * size.horizontalInset(iconType: getIconType(for: self.state)) + baseSize.width, + height: 2 * size.verticalInset(iconType: getIconType(for: self.state)) + baseSize.height ) } - + public override func setTitle(_ title: String?, for state: UIControl.State) { super.setTitle(title, for: state) applyNewTextStyle() } - - public func setLeadingImage(_ image: UIImage, for state: UIControl.State) { - self.setImage(image, for: state) - self.imageView?.tintColor = titleLabel?.textColor - self.tintColor = titleLabel?.textColor - self.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10) - self.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) - self.contentVerticalAlignment = .fill - self.contentMode = .center - self.imageView?.contentMode = .scaleAspectFit - } - - public func setTrailingImage(_ image: UIImage, for state: UIControl.State) { - self.setLeadingImage(image, for: state) - self.semanticContentAttribute = .forceRightToLeft - self.imageEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0) - } - - public func setLeadingImage(_ image: UIImage, for state: UIControl.State, renderingMode: UIImage.RenderingMode) { - guard let resizedImage = image - .resizedImage(size: CGSize(width: 16, height: 16))? - .withRenderingMode(renderingMode) else { return } - self.setLeadingImage(resizedImage, for: state) - } - - public func setTrailingImage(_ image: UIImage, for state: UIControl.State, renderingMode: UIImage.RenderingMode) { - self.setLeadingImage(image, for: state, renderingMode: renderingMode) - self.semanticContentAttribute = .forceRightToLeft - self.imageEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0) - } } // MARK: - Styling @@ -275,17 +259,134 @@ extension VitaminButton.Size { .button } - var horizontalInset: CGFloat { + func horizontalInset(iconType: VitaminButton.IconType) -> CGFloat { + if case .alone(_, _) = iconType { + return 12 + } + switch self { case .medium: return 20 case .large: return 40 } + + } - var verticalInset: CGFloat { + func verticalInset(iconType: VitaminButton.IconType) -> CGFloat { + if case .alone(_, _) = iconType { + return 12 + } + switch self { case .medium: return 16 case .large: return 20 } } + + func defaultIconSize(iconType: VitaminButton.IconType) -> CGFloat { + if case .alone(_, _) = iconType { + switch self { + case .medium : return 24 + case .large: return 32 + } + } else { + switch self { + case .medium : return 20 + case .large: return 24 + } + } + } +} + +// - MARK: Icon managemant + +extension VitaminButton { + public func setIconType(_ iconType: IconType, for state: UIControl.State){ + iconTypes[state] = iconType + applyIcon(for: state) + } + + public func getIconType(for state: UIControl.State) -> IconType { + guard let iconType = iconTypes[state] else { + return iconTypes[.normal] ?? .none + } + return iconType + } + + private func applyIcon(for state: UIControl.State) { + self.invalidateIntrinsicContentSize() + let iconTypeForState = getIconType(for: state) + switch iconTypeForState { + case .none: + break + case .trailing(let image, let renderingMode): + self.commonApplyIcon( + image: image, + iconType: iconTypeForState, + state: state, + renderingMode: renderingMode) + case .leading(let image, let renderingMode): + self.commonApplyIcon( + image: image, + iconType: iconTypeForState, + state: state, + renderingMode: renderingMode) + case .alone(let image, let renderingMode): + self.setTitle("", for: state) + self.commonApplyIcon( + image: image, + iconType: iconTypeForState, + state: state, + renderingMode: renderingMode) + } + } + + private func commonApplyIcon(image: UIImage, iconType: IconType, state: UIControl.State, renderingMode: UIImage.RenderingMode?) { + var imageUpdated = image + if let renderingMode = renderingMode { + guard let resizedImage = image + .resizedImage(size: CGSize(width: self.size.defaultIconSize(iconType: getIconType(for: state)), height: self.size.defaultIconSize(iconType: getIconType(for: state))))? + .withRenderingMode(renderingMode) else { return } + imageUpdated = resizedImage + } + self.setImage(imageUpdated, for: state) + self.imageView?.tintColor = style.foregroundColor + self.tintColor = style.foregroundColor + self.imageEdgeInsets = iconType.imageEdgeInsets + self.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + self.contentVerticalAlignment = .fill + self.contentMode = .center + self.imageView?.contentMode = .scaleAspectFit + } + + private func updateSemantic() { + if case .trailing(_, _) = getIconType(for: self.state){ + self.semanticContentAttribute = .forceRightToLeft + } else { + self.semanticContentAttribute = .forceLeftToRight + } + } + + private func updateImageInsets(){ + self.imageEdgeInsets = self.getIconType(for: self.state).imageEdgeInsets + } +} + +extension VitaminButton.IconType { + var imageEdgeInsets: UIEdgeInsets { + switch self { + case .alone(_, _), .none: + return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + case .trailing(_, _): + return UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0) + case .leading(_, _): + return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10) + } + } +} + +extension UIControl.State: Hashable { + public var hashValue: Int { + self.rawValue.hashValue + } } From 40e1c35c335e13c8782051a331a036d655ef0c41 Mon Sep 17 00:00:00 2001 From: daniel-dumortier Date: Fri, 22 Jul 2022 18:10:56 +0200 Subject: [PATCH 2/5] feat(button) : add icon alone button type, and refactor icon management - swiftlint fixes --- .../Button/Cell/ButtonTableViewCell.swift | 26 ++++++-- .../Components/Button/VitaminButton.swift | 62 +++++++++---------- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.swift b/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.swift index 316ff338..0ded0c53 100644 --- a/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.swift +++ b/Showcase/Application/UIKit/Components/Button/Cell/ButtonTableViewCell.swift @@ -39,11 +39,27 @@ final class ButtonTableViewCell: UITableViewCell { mediumButton.setTitle("\(style)", for: .normal) largeButton.setTitle("\(style)", for: .normal) - - mediumButton.setIconType(.trailing(image: Vitamix.Line.Logos.apple.image, renderingMode: .alwaysTemplate), for: .normal) - largeButton.setIconType(.leading(image: Vitamix.Line.System.arrowRightS.image, renderingMode: .alwaysTemplate), for: .normal) - mediumIconAloneButton.setIconType(.alone(image: Vitamix.Line.Logos.apple.image, renderingMode: .alwaysTemplate), for: .normal) - largeIconAloneButton.setIconType(.alone(image: Vitamix.Line.System.arrowRightS.image, renderingMode: .alwaysTemplate), for: .normal) + + mediumButton.setIconType( + .trailing( + image: Vitamix.Line.Logos.apple.image, + renderingMode: .alwaysTemplate), + for: .normal) + largeButton.setIconType( + .leading( + image: Vitamix.Line.System.arrowRightS.image, + renderingMode: .alwaysTemplate), + for: .normal) + mediumIconAloneButton.setIconType( + .alone( + image: Vitamix.Line.Logos.apple.image, + renderingMode: .alwaysTemplate), + for: .normal) + largeIconAloneButton.setIconType( + .alone( + image: Vitamix.Line.System.arrowRightS.image, + renderingMode: .alwaysTemplate), + for: .normal) mediumButton.isEnabled = isEnabled largeButton.isEnabled = isEnabled diff --git a/Sources/VitaminUIKit/Components/Button/VitaminButton.swift b/Sources/VitaminUIKit/Components/Button/VitaminButton.swift index 6b5d01f5..1368480e 100644 --- a/Sources/VitaminUIKit/Components/Button/VitaminButton.swift +++ b/Sources/VitaminUIKit/Components/Button/VitaminButton.swift @@ -33,15 +33,15 @@ public class VitaminButton: UIButton { applyNewTextStyle() } } - + public enum IconType { case trailing(image: UIImage, renderingMode: UIImage.RenderingMode?) case leading(image: UIImage, renderingMode: UIImage.RenderingMode?) case alone(image: UIImage, renderingMode: UIImage.RenderingMode?) case none } - - private var iconTypes: [UIControl.State:IconType] = [.normal: .none] + + private var iconTypes: [UIControl.State: IconType] = [.normal: .none] public override var isEnabled: Bool { didSet { @@ -64,7 +64,6 @@ public class VitaminButton: UIButton { super.init(frame: .zero) applyNewStyle() applyNewTextStyle() - } public required init?(coder: NSCoder) { @@ -85,7 +84,7 @@ public class VitaminButton: UIButton { height: 2 * size.verticalInset(iconType: getIconType(for: self.state)) + baseSize.height ) } - + public override func setTitle(_ title: String?, for state: UIControl.State) { super.setTitle(title, for: state) applyNewTextStyle() @@ -260,31 +259,29 @@ extension VitaminButton.Size { } func horizontalInset(iconType: VitaminButton.IconType) -> CGFloat { - if case .alone(_, _) = iconType { + if case .alone = iconType { return 12 } - + switch self { case .medium: return 20 case .large: return 40 } - - } func verticalInset(iconType: VitaminButton.IconType) -> CGFloat { - if case .alone(_, _) = iconType { + if case .alone = iconType { return 12 } - + switch self { case .medium: return 16 case .large: return 20 } } - + func defaultIconSize(iconType: VitaminButton.IconType) -> CGFloat { - if case .alone(_, _) = iconType { + if case .alone = iconType { switch self { case .medium : return 24 case .large: return 32 @@ -301,37 +298,37 @@ extension VitaminButton.Size { // - MARK: Icon managemant extension VitaminButton { - public func setIconType(_ iconType: IconType, for state: UIControl.State){ + public func setIconType(_ iconType: IconType, for state: UIControl.State) { iconTypes[state] = iconType applyIcon(for: state) } - + public func getIconType(for state: UIControl.State) -> IconType { guard let iconType = iconTypes[state] else { return iconTypes[.normal] ?? .none } return iconType } - + private func applyIcon(for state: UIControl.State) { self.invalidateIntrinsicContentSize() let iconTypeForState = getIconType(for: state) switch iconTypeForState { case .none: break - case .trailing(let image, let renderingMode): + case let .trailing(image, renderingMode): self.commonApplyIcon( image: image, iconType: iconTypeForState, state: state, renderingMode: renderingMode) - case .leading(let image, let renderingMode): + case let .leading(image, renderingMode): self.commonApplyIcon( image: image, iconType: iconTypeForState, state: state, renderingMode: renderingMode) - case .alone(let image, let renderingMode): + case let .alone(image, renderingMode): self.setTitle("", for: state) self.commonApplyIcon( image: image, @@ -340,13 +337,16 @@ extension VitaminButton { renderingMode: renderingMode) } } - + private func commonApplyIcon(image: UIImage, iconType: IconType, state: UIControl.State, renderingMode: UIImage.RenderingMode?) { var imageUpdated = image if let renderingMode = renderingMode { guard let resizedImage = image - .resizedImage(size: CGSize(width: self.size.defaultIconSize(iconType: getIconType(for: state)), height: self.size.defaultIconSize(iconType: getIconType(for: state))))? - .withRenderingMode(renderingMode) else { return } + .resizedImage( + size: CGSize( + width: self.size.defaultIconSize(iconType: getIconType(for: state)), + height: self.size.defaultIconSize(iconType: getIconType(for: state))))? + .withRenderingMode(renderingMode) else { return } imageUpdated = resizedImage } self.setImage(imageUpdated, for: state) @@ -358,16 +358,16 @@ extension VitaminButton { self.contentMode = .center self.imageView?.contentMode = .scaleAspectFit } - + private func updateSemantic() { - if case .trailing(_, _) = getIconType(for: self.state){ + if case .trailing = getIconType(for: self.state) { self.semanticContentAttribute = .forceRightToLeft } else { self.semanticContentAttribute = .forceLeftToRight } } - - private func updateImageInsets(){ + + private func updateImageInsets() { self.imageEdgeInsets = self.getIconType(for: self.state).imageEdgeInsets } } @@ -375,18 +375,18 @@ extension VitaminButton { extension VitaminButton.IconType { var imageEdgeInsets: UIEdgeInsets { switch self { - case .alone(_, _), .none: + case .alone, .none: return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) - case .trailing(_, _): + case .trailing: return UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0) - case .leading(_, _): + case .leading: return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10) } } } extension UIControl.State: Hashable { - public var hashValue: Int { - self.rawValue.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(self.rawValue.hashValue) } } From a2c00d217749b5c5c9baad3230fbfe55997bdd9f Mon Sep 17 00:00:00 2001 From: daniel-dumortier Date: Fri, 22 Jul 2022 18:27:01 +0200 Subject: [PATCH 3/5] feat(button) : add icon alone button type - fix whitespaces in README --- Sources/VitaminUIKit/Components/Button/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/VitaminUIKit/Components/Button/README.md b/Sources/VitaminUIKit/Components/Button/README.md index 09aa7743..781b7fb2 100644 --- a/Sources/VitaminUIKit/Components/Button/README.md +++ b/Sources/VitaminUIKit/Components/Button/README.md @@ -29,15 +29,15 @@ You can put an icon from Vitamin icons library in your button, or also have a sq To achieve this, `VitaminButton` provides you with a `setIconType(:for:)` method. You can have different icons, or even different icon types per state. -`IconType` has four cases : -- `.leading` : icon will be put before your button label -- `.trailing` : icon will be put after your button label -- `.alone` : button will be squared, an icon will be centered, and no button label will be displayed -- `.none` : no icon will be displayed in your button +`IconType` has four cases: +- `.leading`: icon will be put before your button label +- `.trailing`: icon will be put after your button label +- `.alone`: button will be squared, an icon will be centered, and no button label will be displayed +- `.none`: no icon will be displayed in your button -For `.leading`, `.trailing` and `.alone`, you must provide : +For `.leading`, `.trailing` and `.alone`, you must provide: - an `UIImage` from Vitamin icons library (but will work with any UIImage) -- an optional `UIImage.RenderingMode` : if you provide one, image will be resized using this rendering mode, if not, image will be used as is (with unexpected behaviour if your image has a wrong size) +- an optional `UIImage.RenderingMode`: if you provide one, image will be resized using this rendering mode, if not, image will be used as is (with unexpected behaviour if your image has a wrong size) If you do not specify specific icon type for a specific state, the one for .normal state will be chosen. And by default, the icon type for .normal state is .none From 20d08942380500e9a20b8dfaf48467f4a4301fbc Mon Sep 17 00:00:00 2001 From: Daniel DUMORTIER <43171132+daniel-dumortier@users.noreply.github.com> Date: Mon, 25 Jul 2022 09:39:31 +0200 Subject: [PATCH 4/5] feat(button): add icon alone UIKit VitaminButton type - PR reviews MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Florent LOTTHÉ --- Sources/VitaminUIKit/Components/Button/README.md | 4 ++-- Sources/VitaminUIKit/Components/Button/VitaminButton.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/VitaminUIKit/Components/Button/README.md b/Sources/VitaminUIKit/Components/Button/README.md index 781b7fb2..56eb0d15 100644 --- a/Sources/VitaminUIKit/Components/Button/README.md +++ b/Sources/VitaminUIKit/Components/Button/README.md @@ -39,8 +39,8 @@ For `.leading`, `.trailing` and `.alone`, you must provide: - an `UIImage` from Vitamin icons library (but will work with any UIImage) - an optional `UIImage.RenderingMode`: if you provide one, image will be resized using this rendering mode, if not, image will be used as is (with unexpected behaviour if your image has a wrong size) -If you do not specify specific icon type for a specific state, the one for .normal state will be chosen. -And by default, the icon type for .normal state is .none +If you do not specify specific icon type for a specific state, the one for `.normal` state will be chosen. +And by default, the icon type for `.normal` state is `.none`. Note: squareness of VitaminButton with `.alone` is handled through intrisicSize, it is not guaranteed if you apply constants that could impact width and height of button. diff --git a/Sources/VitaminUIKit/Components/Button/VitaminButton.swift b/Sources/VitaminUIKit/Components/Button/VitaminButton.swift index 1368480e..07ed5836 100644 --- a/Sources/VitaminUIKit/Components/Button/VitaminButton.swift +++ b/Sources/VitaminUIKit/Components/Button/VitaminButton.swift @@ -329,7 +329,7 @@ extension VitaminButton { state: state, renderingMode: renderingMode) case let .alone(image, renderingMode): - self.setTitle("", for: state) + self.setTitle(nil, for: state) self.commonApplyIcon( image: image, iconType: iconTypeForState, From 695e0fdc250a64e7b1d35899c80afa21d3151b14 Mon Sep 17 00:00:00 2001 From: Daniel DUMORTIER <43171132+daniel-dumortier@users.noreply.github.com> Date: Mon, 25 Jul 2022 09:42:53 +0200 Subject: [PATCH 5/5] feat(button): add icon alone UIKit VitaminButton type - PR reviews MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Florent LOTTHÉ --- Sources/VitaminUIKit/Components/Button/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/VitaminUIKit/Components/Button/README.md b/Sources/VitaminUIKit/Components/Button/README.md index 56eb0d15..00e67991 100644 --- a/Sources/VitaminUIKit/Components/Button/README.md +++ b/Sources/VitaminUIKit/Components/Button/README.md @@ -36,7 +36,7 @@ You can have different icons, or even different icon types per state. - `.none`: no icon will be displayed in your button For `.leading`, `.trailing` and `.alone`, you must provide: -- an `UIImage` from Vitamin icons library (but will work with any UIImage) +- an `UIImage` from Vitamin icons library (but will work with any `UIImage`) - an optional `UIImage.RenderingMode`: if you provide one, image will be resized using this rendering mode, if not, image will be used as is (with unexpected behaviour if your image has a wrong size) If you do not specify specific icon type for a specific state, the one for `.normal` state will be chosen.