SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.2k stars 228 forks source link

How to make Image circle? #69

Closed phuongphally closed 4 years ago

dreampiggy commented 4 years ago

Could you please explain whay you means for Image Circle ? I can not get the point.

If you means the Image View Circle clip, you can already use the mask, or corner radius to clicp any SwiftUI View to become a Circle avatar. Check Apple’s SwiftUI toturial for this.

If you mean custom transformer to clip original image to a circle, use SDWebImageCornerRadiusTransformer, which may suit for this task

phuongphally commented 4 years ago

@dreampiggy I means the Image View Circle clip. Because I'm new to Swift and IOS , now I solve to

            WebImage(url: URL(string:  url)!)
               .onSuccess { image, cacheType in
                   // Success
               }
               .resizable() // Resizable like SwiftUI.Image
               .placeholder(Image(systemName: "photo")) // Placeholder Image
               // Supports ViewBuilder as well
               .placeholder {
                   Rectangle().foregroundColor(.gray)
               }
               .animated() // Supports Animated Image
               .indicator(.activity) // Activity Indicator
               .animation(.easeInOut(duration: 0.5)) // Animation Duration
               .transition(.fade) // Fade Transition
               .scaledToFit()
               .clipShape(Circle())
               .shadow(radius: 10)
               .frame(width: 50, height: 50, alignment: .center)

add this

               .scaledToFit()
               .clipShape(Circle())
dreampiggy commented 4 years ago

Yes. WebImage is just a normal SwiftUI view and compatible for all SwiftUI layout system.

Seems you already solve the issue ? Close this ?


Semes it's time to close. Feel free to reopen this issue if you still have problem ;)