Skip to content

Commit

Permalink
Fixed layout in buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Aug 15, 2021
1 parent 793400c commit 17bf49d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ open class SPLargeActionButton: SPDimmedButton {
titleLabel?.font = UIFont.preferredFont(forTextStyle: .headline, addPoints: 1)
titleLabel?.numberOfLines = 1
titleImageInset = 6
contentEdgeInsets = .init(horizontal: 10, vertical: .zero)
}

// MARK: - Public
Expand Down Expand Up @@ -72,7 +73,18 @@ open class SPLargeActionButton: SPDimmedButton {
}

open override func sizeThatFits(_ size: CGSize) -> CGSize {
return CGSize(width: size.width, height: 50)
let superSize = super.sizeThatFits(size)
let width = superSize.width

var height = superSize.height + 28
if let titleLabel = titleLabel, let imageView = imageView, let _ = imageView.image {
if titleLabel.frame.height > 0 && imageView.frame.height > 0 {
let imageCorrection = imageView.frame.height - titleLabel.frame.height
height -= imageCorrection
}
}

return CGSize(width: width, height: height)
}

// MARK: - Ovveride
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ open class SPSmallActionButton: SPDimmedButton {
SparrowKit: Wrapper of set content and color of button.
- parameter title: Text which using like title.
- parameter icon: Object of `UIImage`, using like icon.
- parameter icon: Object of `UIImage`, using like icon. Usually Apple doesn't use icon in this button.
- parameter colorise: Color of button in default state.
*/
public func set(title: String, icon: UIImage?, colorise: SPDimmedButton.Colorise) {
public func set(title: String, icon: UIImage? = nil, colorise: SPDimmedButton.Colorise) {
setTitle(title)
if let icon = icon {
setImage(icon.alwaysTemplate)
Expand All @@ -84,6 +84,7 @@ open class SPSmallActionButton: SPDimmedButton {
height -= imageCorrection
}
}

return CGSize(width: width, height: height)
}

Expand Down

0 comments on commit 17bf49d

Please sign in to comment.