如何使顶部图像不透明,这样背景图像就不会显示出来?
How do I make the top image not transparent so the background image doesn't show through?
我有一个 UIImage 视图,然后是一个叠加视图,然后是另一个 UIImage 视图。我需要顶部的 UIImageView 完全不透明。我不想看到任何背景图片。
我试过设置 alpha,我试过将混合处理器与 Kingfisher 一起使用,我试过将 png 转换为 jpg,我试过将一个子视图移到另一个子视图的前面,我试过更改背景颜色图像,我尝试将顶部图像设置为不透明而不是不透明,因为我阅读了不同的东西,我尝试了很多东西。
clientProfileImg.borderWidth = 2.0
clientProfileImg.borderColor = UIColor.white
clientProfileImg.isUserInteractionEnabled = false
clientBackgroundProfileImg.isUserInteractionEnabled = false
view.bringSubview(toFront: clientProfileImg)
view.sendSubview(toBack: clientBackgroundProfileImg)
clientProfileImg.backgroundColor = UIColor.black
clientProfileImg.alpha = 1.0
guard let profilePic = client?.profilePhoto else { print("No profile pic"); return }
let resource = ImageResource(downloadURL: URL(string: profilePic)!, cacheKey: profilePic)
// Blend (iOS)
// let processor = BlendImageProcessor(blendMode: .sourceAtop, alpha: 1.0, backgroundColor: .black)
// Set the image to Kingfisher which caches it
DispatchQueue.main.async {
self.clientProfileImg.kf.setImage(with: resource, placeholder: #imageLiteral(resourceName: "user-gray"), options: [.forceRefresh, .cacheSerializer(FormatIndicatedCacheSerializer.jpeg)])
self.clientBackgroundProfileImg.kf.setImage(with: resource, options: [.forceRefresh,
.cacheSerializer(FormatIndicatedCacheSerializer.jpeg)]
}
这是我看到的:
这是我想要的:
尝试使用方法
withRenderingMode(_:)
三个渲染模式值..
.automatic (default)
.alwaysOriginal
.alwaysTemplate
我解决了,实际上故事板中它们之间有一个叠加图像。删除它并在运行时以编程方式添加它解决了这个问题
我有一个 UIImage 视图,然后是一个叠加视图,然后是另一个 UIImage 视图。我需要顶部的 UIImageView 完全不透明。我不想看到任何背景图片。
我试过设置 alpha,我试过将混合处理器与 Kingfisher 一起使用,我试过将 png 转换为 jpg,我试过将一个子视图移到另一个子视图的前面,我试过更改背景颜色图像,我尝试将顶部图像设置为不透明而不是不透明,因为我阅读了不同的东西,我尝试了很多东西。
clientProfileImg.borderWidth = 2.0
clientProfileImg.borderColor = UIColor.white
clientProfileImg.isUserInteractionEnabled = false
clientBackgroundProfileImg.isUserInteractionEnabled = false
view.bringSubview(toFront: clientProfileImg)
view.sendSubview(toBack: clientBackgroundProfileImg)
clientProfileImg.backgroundColor = UIColor.black
clientProfileImg.alpha = 1.0
guard let profilePic = client?.profilePhoto else { print("No profile pic"); return }
let resource = ImageResource(downloadURL: URL(string: profilePic)!, cacheKey: profilePic)
// Blend (iOS)
// let processor = BlendImageProcessor(blendMode: .sourceAtop, alpha: 1.0, backgroundColor: .black)
// Set the image to Kingfisher which caches it
DispatchQueue.main.async {
self.clientProfileImg.kf.setImage(with: resource, placeholder: #imageLiteral(resourceName: "user-gray"), options: [.forceRefresh, .cacheSerializer(FormatIndicatedCacheSerializer.jpeg)])
self.clientBackgroundProfileImg.kf.setImage(with: resource, options: [.forceRefresh,
.cacheSerializer(FormatIndicatedCacheSerializer.jpeg)]
}
这是我看到的:
这是我想要的:
尝试使用方法
withRenderingMode(_:)
三个渲染模式值..
.automatic (default)
.alwaysOriginal
.alwaysTemplate
我解决了,实际上故事板中它们之间有一个叠加图像。删除它并在运行时以编程方式添加它解决了这个问题