You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
//
|
|
// userPicture.swift
|
|
// AllIn
|
|
//
|
|
// Created by Lucas Delanier on 04/06/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct UserPicture: View {
|
|
var picture: String?
|
|
var username: String
|
|
var size: CGFloat
|
|
var body: some View {
|
|
ZStack {
|
|
if picture != nil {
|
|
AsyncImage(
|
|
url: URL(string:picture!),
|
|
content: { image in
|
|
image
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fit)
|
|
.clipShape(Circle())
|
|
},
|
|
placeholder: {
|
|
ProgressView()
|
|
}
|
|
)
|
|
} else {
|
|
Circle()
|
|
.foregroundColor(.gray)
|
|
.frame(width: size, height: size)
|
|
.overlay(
|
|
Text(username.prefix(2).uppercased())
|
|
.fontWeight(.medium)
|
|
.foregroundStyle(.white)
|
|
.font(.system(size: fontSize(for: size)))
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
func fontSize(for diameter: CGFloat) -> CGFloat {
|
|
let fontScaleFactor: CGFloat = 0.45
|
|
return diameter * fontScaleFactor
|
|
}
|
|
}
|
|
|
|
struct UserPicture_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
UserPicture(picture: nil, username: "Lucas", size: 100)
|
|
}
|
|
}
|