Skip to content

Commit 66d672f

Browse files
committed
💄 Add better padding calculation
1 parent 477d8a2 commit 66d672f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Sources/InitialsUI/InitialsUI.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,22 @@ public struct InitialsUI<Content: View>: View {
4949
.font(.system(size: g.size.width * 0.8))
5050
.fontWeight(fontWeight)
5151
.modifier(FitToWidth())
52-
.padding(g.size.width > 100 ? 20 : 0)
52+
.padding(calculatePadding(width: g.size.width))
5353
}
5454
}
5555
}
56+
57+
private func calculatePadding(width: CGFloat) -> CGFloat {
58+
if (width <= 50 && initials.count > 1) {
59+
return 2
60+
}
61+
62+
if (width <= 100) {
63+
return 5
64+
}
65+
66+
return 20
67+
}
5668
}
5769

5870
extension InitialsUI {
@@ -122,7 +134,7 @@ extension InitialsUI where Content == Color {
122134
/// - Parameter fontWeight: The font weight used on the initials
123135
/// - Parameter randomBackground: Use a random background
124136
///
125-
/// - Returns: A view with the initials from provided the string
137+
/// - Returns: A view with the initials from provided the initials
126138
///
127139
/// - warning: If you don't want to use random backgrounds, use a different initializer!
128140
public init(initials: String,
@@ -211,7 +223,7 @@ struct FitToWidth: ViewModifier {
211223
// MARK: Color randomization methods
212224

213225
func randomColorComponent() -> Int {
214-
let limit = 30 - 214
226+
let limit = 214 - 30
215227
return 30 + Int(drand48() * Double(limit))
216228
}
217229

0 commit comments

Comments
 (0)