I am currently working on a SwiftUI Chat View project, and I am trying to round the corner of an image, which is loaded via a URL and converted from UIImage to Image. Any ideas why .cornerRadius(10) isn't working?
Image(uiImage: imageFromFirebase!)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: UIScreen.main.bounds.width / 1.5, alignment: isCurrentUser ? .trailing : .leading)
.clipped()
.cornerRadius(10)
Here is the full container – there is probably a lot of unnecessary stuff here but in case it helps:
struct ContentMessageView: View {
var contentMessage: String
var isCurrentUser: Bool
var type: String
var name: String
var color: Color
var image: UIImage?
@State private var imageFromFirebase: UIImage?
func imageLoadFromURL(){
HTTPRequest.fetchImage(self.contentMessage) { (image) in
if image != nil {
imageFromFirebase = image!
}
}
}
var body: some View {
VStack{
if type == "image" {
if !isCurrentUser {
HStack{
Text(name).font(.caption).foregroundColor(Color.black.opacity(0.2)).padding(.horizontal)
Spacer()
}
}
HStack{
if isCurrentUser {
Spacer()
}
if imageFromFirebase != nil {
ZStack{
Image(uiImage: imageFromFirebase!)
.resizable()
.scaledToFit()
.cornerRadius(10)
.frame(width: UIScreen.main.bounds.width / 1.5, alignment: isCurrentUser ? .trailing : .leading)
// .overlay(RoundedRectangle(cornerRadius: 10)
.background(Color.black)
// .stroke(isCurrentUser ? Color(UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 1.0)) : color, lineWidth: 5))
}
.shadow(color: Color.black.opacity(0.05), radius: 10)
}
if !isCurrentUser {
Spacer()
}
}.padding(.horizontal, 10)
}
}.onAppear(){
self.imageLoadFromURL()
}
}
}
UIImage
, right? I just updated the post with the full view