如何使顶部图像不透明,以便背景图像不显示?

问题描述 投票:0回答:2

我有一个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)] 

  }

这是我看到的:

这就是我想要的:

ios swift uiimageview uiimage overlay
2个回答
0
投票

尝试使用该方法

withRenderingMode(_ :)

三种渲染模式值..

.automatic (default)
.alwaysOriginal
.alwaysTemplate

0
投票

我解决了它,实际上它们在故事板中有一个叠加图像。删除它并在运行时以编程方式添加它修复了此问题

© www.soinside.com 2019 - 2024. All rights reserved.