History
Loading...
Loading...
September 30, 2025
.clipShape() instead of .clipped() when you want to apply a specific shape boundary to your content. While .clipped() only clips to rectangular bounds, .clipShape(Circle()) or .clipShape(RoundedRectangle(cornerRadius: 10)) gives you precise control over the clipping boundary.This pattern ensures that images always maintain their intended shape boundaries while providing a subtle visual enhancement with the stroke overlay. The clipping prevents any content overflow that could break the intended circular design.
struct ProfileImageView: View {
let imageURL: String
let size: CGFloat
var body: some View {
AsyncImage(url: URL(string: imageURL)) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
} placeholder: {
Color.gray.opacity(0.3)
}
.frame(width: size, height: size)
.clipShape(Circle())
.overlay {
Circle()
.stroke(Color.primary.opacity(0.1), lineWidth: 1)
}
}
}Clipping modifiers are essential for maintaining clean visual boundaries, especially when dealing with dynamic content like user-uploaded images. The overlay addition provides a professional polish that works across different color schemes and image types.