ios 学习Swift和Xcode,在语法中遇到问题

dxxyhpgq  于 2023-07-01  发布在  iOS
关注(0)|答案(2)|浏览(109)
AsyncImage(url: URL(string: imageURL)) { image in
   image
} placeholder: {
   Image(systemName: "photo.circle.fill")
}
.padding(40)

我试图在图像中使用图像,但它不起作用。还有,填充物也不起作用。

ar5n3qh5

ar5n3qh51#

var defaultImage: Image = Image("add-user")
AsyncImage(url: URL(string: imageUrl )) { image in
    image.resizable().aspectRatio(contentMode: .fill).frame(width: 120, height: 120).background(Color.red).cornerRadius(60)
}placeholder: {
        defaultImage.resizable().aspectRatio(contentMode: .fill).cornerRadius(60).frame(width: 120, height: 120)
}
sgtfey8w

sgtfey8w2#

你看起来像这样吗

extension UIImageView {
    func setImage(fromUrl:String?) {
        let placeholderImage : UIImage = UIImage(systemName: "photo.circle.fill")!
        self.image = placeholderImage
        guard let url = URL(string: ~fromUrl?.replacingOccurrences(of: " ", with: "")) else {
            return
        }
        let request = ImageRequest(
            url: url,
            processors: [ImageProcessors.Resize(size: self.bounds.size)],
            priority: .veryHigh
        )
        let options = ImageLoadingOptions(placeholder: placeholderImage, transition: nil, failureImage: placeholderImage, failureImageTransition: nil)
        Nuke.loadImage(with: request, options: options, into: self, progress: nil) { _ in}
    }
}

相关问题