Skip to content

Commit 17bf49d

Browse files
committed
Fixed layout in buttons.
1 parent 793400c commit 17bf49d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Sources/SparrowKit/UIKit/Classes/Buttons/SPLargeActionButton.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ open class SPLargeActionButton: SPDimmedButton {
4545
titleLabel?.font = UIFont.preferredFont(forTextStyle: .headline, addPoints: 1)
4646
titleLabel?.numberOfLines = 1
4747
titleImageInset = 6
48+
contentEdgeInsets = .init(horizontal: 10, vertical: .zero)
4849
}
4950

5051
// MARK: - Public
@@ -72,7 +73,18 @@ open class SPLargeActionButton: SPDimmedButton {
7273
}
7374

7475
open override func sizeThatFits(_ size: CGSize) -> CGSize {
75-
return CGSize(width: size.width, height: 50)
76+
let superSize = super.sizeThatFits(size)
77+
let width = superSize.width
78+
79+
var height = superSize.height + 28
80+
if let titleLabel = titleLabel, let imageView = imageView, let _ = imageView.image {
81+
if titleLabel.frame.height > 0 && imageView.frame.height > 0 {
82+
let imageCorrection = imageView.frame.height - titleLabel.frame.height
83+
height -= imageCorrection
84+
}
85+
}
86+
87+
return CGSize(width: width, height: height)
7688
}
7789

7890
// MARK: - Ovveride

Sources/SparrowKit/UIKit/Classes/Buttons/SPSmallActionButton.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ open class SPSmallActionButton: SPDimmedButton {
5454
SparrowKit: Wrapper of set content and color of button.
5555

5656
- parameter title: Text which using like title.
57-
- parameter icon: Object of `UIImage`, using like icon.
57+
- parameter icon: Object of `UIImage`, using like icon. Usually Apple doesn't use icon in this button.
5858
- parameter colorise: Color of button in default state.
5959
*/
60-
public func set(title: String, icon: UIImage?, colorise: SPDimmedButton.Colorise) {
60+
public func set(title: String, icon: UIImage? = nil, colorise: SPDimmedButton.Colorise) {
6161
setTitle(title)
6262
if let icon = icon {
6363
setImage(icon.alwaysTemplate)
@@ -84,6 +84,7 @@ open class SPSmallActionButton: SPDimmedButton {
8484
height -= imageCorrection
8585
}
8686
}
87+
8788
return CGSize(width: width, height: height)
8889
}
8990

0 commit comments

Comments
 (0)