Skip to content

A simple SwiftUI View for using initials as profile images.

License

Notifications You must be signed in to change notification settings

lovetodream/InitialsUI

Repository files navigation

GitHub release (latest SemVer) GitHub Platforms

InitialsUI

A simple SwiftUI View for using initials as profile images.

🚩 Features

  • 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)

📸 Screenshots

Example Screenshot

🔧 Installation

Install with Swift Package Manager

https://github.com/lovetodream/InitialsUI

✨ Usage/Examples

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

📝 Documentation

Initializes a InitialsUI View from 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 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)

Initializes a InitialsUI View from the provided initials

  • 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

⚠️ If you don't want to use random backgrounds, use a different initializer!

  • 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)

Initializes a InitialsUI View with a random background color using the provided initials

⚠️ If you don't want to use random backgrounds, use a different initializer!

  • 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

⚠️ This initializer applies a gray background color by default!

  • 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)

Initializes a InitialsUI View from the provided initials with gray background

⚠️ This initializer applies a gray background color by default!

  • 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)

About

A simple SwiftUI View for using initials as profile images.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages