File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,22 @@ public struct InitialsUI<Content: View>: View {
49
49
. font ( . system( size: g. size. width * 0.8 ) )
50
50
. fontWeight ( fontWeight)
51
51
. modifier ( FitToWidth ( ) )
52
- . padding ( g. size. width > 100 ? 20 : 0 )
52
+ . padding ( calculatePadding ( width : g. size. width) )
53
53
}
54
54
}
55
55
}
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
+ }
56
68
}
57
69
58
70
extension InitialsUI {
@@ -122,7 +134,7 @@ extension InitialsUI where Content == Color {
122
134
/// - Parameter fontWeight: The font weight used on the initials
123
135
/// - Parameter randomBackground: Use a random background
124
136
///
125
- /// - Returns: A view with the initials from provided the string
137
+ /// - Returns: A view with the initials from provided the initials
126
138
///
127
139
/// - warning: If you don't want to use random backgrounds, use a different initializer!
128
140
public init ( initials: String ,
@@ -211,7 +223,7 @@ struct FitToWidth: ViewModifier {
211
223
// MARK: Color randomization methods
212
224
213
225
func randomColorComponent( ) -> Int {
214
- let limit = 30 - 214
226
+ let limit = 214 - 30
215
227
return 30 + Int( drand48 ( ) * Double( limit) )
216
228
}
217
229
You can’t perform that action at this time.
0 commit comments