A simple SwiftUI View for using initials as profile images.
- Initials are calculated automatically
- Initials text size adjusts automatically
- Fully customizable initials font weight
- Fully customizable foreground color
- Fully customizable background
- Fully customizable corner radius
- Fully customizable border
- Random background colors
- Can be used with a Binding
- Cross platform >= SwiftUI 1 (macOS 10.15, iOS 13, watchOS 6, tvOS 13)
Install with Swift Package Manager
https://github.com/lovetodream/InitialsUI
Basic usage
import SwiftUI
import InitialsUI
struct ContentView: View {
public var body: some View {
VStack {
InitialsUI(initials: "JD")
}
}
}
Basic usage with full name
...
struct ContentView: View {
@State private var name = "John Doe"
public var body: some View {
VStack {
InitialsUI(text: $name)
}
}
}
Further information here
- Parameter
text
: The text used to create the initials - Parameter
useDefaultForegroundColor
: Use the default color white for the initials - Parameter
fontWeight
: The font weight used on the initials - Parameter
background
: Any view as the background
Returns a view with the initials from provided the string
InitialsUI(text: Binding<String>, useDefaultForegroundColor: Bool = true, fontWeight: Font.Weight? = nil, background: @escaping () -> Content)
- Parameter
initials
: The initials - Parameter
useDefaultForegroundColor
: Use the default color white for the initials - Parameter
fontWeight
: The font weight used on the initials - Parameter
background
: Any view as the background
Returns a view with the provided initials
InitialsUI(initials: String, useDefaultForegroundColor: Bool = true, fontWeight: Font.Weight? = nil, background: @escaping () -> Content)
Initializes a InitialsUI View with a random background color using the first letter of every word from a string
- Parameter
text
: The text used to create the initials - Parameter
useDefaultForegroundColor
: Use the default color white for the initials - Parameter
fontWeight
: The font weight used on the initials - Parameter
randomBackground
: Use a random background
Returns a view with the initials from provided the string
InitialsUI(text: Binding<String>, useDefaultForegroundColor: Bool = true, fontWeight: Font.Weight? = nil, randomBackground: Bool)
- Parameter
initials
: The initials - Parameter
useDefaultForegroundColor
: Use the default color white for the initials - Parameter
fontWeight
: The font weight used on the initials - Parameter
randomBackground
: Use a random background
Returns a view with the initials from provided the initials
InitialsUI(initials: String, useDefaultForegroundColor: Bool = true, fontWeight: Font.Weight? = nil, randomBackground: Bool)
Initializes a InitialsUI View from the first letter of every word from a string with gray background
- Parameter
text
: The text used to create the initials - Parameter
useDefaultForegroundColor
: Use the default color white for the initials - Parameter
fontWeight
: The font weight used on the initials
Returns a view with the initials from provided the string
InitialsUI(text: Binding<String>, useDefaultForegroundColor: Bool = true, fontWeight: Font.Weight? = nil)
- Parameter `initials: The initials
- Parameter
useDefaultForegroundColor
: Use the default color white for the initials - Parameter
fontWeight
: The font weight used on the initials
Returns a view with the initials from provided the string
InitialsUI(initials: String, useDefaultForegroundColor: Bool = true, fontWeight: Font.Weight? = nil)