【问题标题】:How do I make the top image not transparent so the background image doesn't show through?如何使顶部图像不透明,使背景图像不显示?
【发布时间】:2019-09-02 14:40:32
【问题描述】:

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


    【解决方案1】:

    尝试使用方法

    withRenderingMode(_:)

    三种渲染模式值..

    .automatic (default)
    .alwaysOriginal
    .alwaysTemplate
    

    【讨论】:

    • 我解决了,实际上故事板中它们之间有一个叠加图像。删除它并在运行时以编程方式添加它解决了这个问题。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2011-02-05
      • 2017-10-13
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多