Avatar View
Display user avatars from URLs or Gravatar emails. Automatically shows a default avatar if the image fails to load.
AvatarView(
url: URL(string: "https://example.com/avatar.jpg")
)
.frame(width: 50, height: 50)
Copied!
Gravatar Email
Generate avatar from a Gravatar email address. The component automatically creates the Gravatar URL and handles the MD5 hash. You can optionally specify the size parameter to control the image resolution.
// Default resolution (Gravatar default)
AvatarView(
gravatar: "user@example.com"
)
.frame(width: 50, height: 50)
// Custom resolution
AvatarView(
gravatar: "user@example.com",
size: 200
)
.frame(width: 50, height: 50)
Copied!
Gravatar with Default Image
Provide a custom default image URL that Gravatar will use if no avatar is found for the email address.
AvatarView(
gravatar: "user@example.com",
size: 100,
defaultImage: "https://via.placeholder.com/200"
)
.frame(width: 50, height: 50)
Copied!
Circular Avatar
Use SwiftUI modifiers to style the avatar, such as making it circular with cornerRadius.
AvatarView(
gravatar: "user@example.com"
)
.frame(width: 50, height: 50)
.cornerRadius(25)
Copied!
Default Avatar Fallback
If the image fails to load or the email is nil, the component automatically displays a default avatar image from the Dejavu bundle.
AvatarView(
gravatar: nil,
size: 200
)
.frame(width: 50, height: 50)
Copied!