Swiftpack.co - Package - liang2kl/AvatarX

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.


Generate GitHub-style pixel avatars, with SwiftUI.


Generate GitHub-style pixel avatars, with SwiftUI.


To create an avatar view, simply initialize an Avatar instance with a hashable value and the configuration specifying colors and the resolution:

    configuration: AvatarConfiguration(colors: [.white, .blue, .green], resolution: 6), 
    value: 0

You can also specify whether to apply a symmetric style in the configuration, which is true by default:

public struct AvatarConfiguration {
    public var symmetric: Bool


You can customize AvatarX by implementing wrappers with a Hashable generic type, or a concrete type conforming to Hashable.

For example, to apply padding around the avatar using one of the colors:

struct AvatarWrapper<HashableValue>: View where HashableValue: Hashable {
    var colors: [Color]
    var resolution: Int
    var symmetric: Bool = true
    var padding: CGFloat = 0
    var value: HashableValue
    var body: some View {
            configuration: AvatarConfiguration(
                colors: colors,
                resolution: resolution,
                symmetric: symmetric
            value: value
        .background(colors.count >= 1 ? colors[0] : nil)


Stars: 1
Last commit: 1 week ago