【问题标题】:iOS 12 Photos App video thumbnail label gradient issueiOS 12 Photos App 视频缩略图标签渐变问题
【发布时间】:2019-12-10 09:23:16
【问题描述】:

iOS 12 上的照片库在缩略图上放置了某种棘手的渐变背景,以显示视频时长标签。我录制了一个纯白色背景视频,标签有白色到黑色的渐变。但在其他缩略图上,渐变是不同的。想知道这里应用的技术是什么?他们如何根据缩略图为渐变选择颜色?

甚至 WhatsApp 都有一个自定义渐变,可以在图像上显示日期。如果 iOS 上的 Photos App 使用的渐变很难找到,任何替代的渐变解决方案都是好的,只要它不破坏。

【问题讨论】:

    标签: ios uikit calayer cagradientlayer


    【解决方案1】:

    我不认为它只是黑到白。它看起来更像是黑色 alpha 1 到白色 alpha 0。也许黑色 alpha 0.5 到白色 alpha 0。玩弄精确的值,但这就是要点。

    【讨论】:

      【解决方案2】:

      我可以很容易地重新创建这个简单的渐变,从顶部的176,176,176,0 到底部的49,49,49,1

      【讨论】:

      • Stack Overflow 不是“为我编写代码”服务。你问到创建一个在视觉上与照片中的渐变相匹配的渐变,如果在代码中使用,我在这里展示的颜色/渐变绝对可以工作。我没有编写 Swift 代码来生成渐变(看起来和其他人一样),但是当这些渐变绝对可以时回答“似乎不起作用”是一种误导。
      • 你能分享第二个图案图像吗?我可以通过生成视频来测试它是否在照片库中匹配?
      【解决方案3】:

      如果你想试试。

      • UiImageView 倒向UILabel
      • 并在UiImageView 中设置下图。

      • 并将UiLabel 设置在UiImageView 之上,在我的最后一项任务中它对我很有帮助;)。

      【讨论】:

        【解决方案4】:

        这里我使用为渐变创建扩展

        @IBDesignable
        class GradientView: UIView {
            @IBInspectable var firstColor: UIColor = UIColor.clear {
                didSet {
                    updateGradientView()
                }
            }
        
            @IBInspectable var secondColor: UIColor = UIColor.clear {
                didSet {
                    updateGradientView()
                }
            }
        
            @IBInspectable var thirdColor: UIColor = UIColor.clear {
                didSet {
                    updateGradientView()
                }
            }
        
            override class var layerClass: AnyClass {
                get {
                    return CAGradientLayer.self
                }
            }
        
            @IBInspectable var isHorizontal: Bool = true {
                didSet {
                    updateGradientView()
                }
            }
        
            func updateGradientView() {
                let gradientLayer = self.layer as! CAGradientLayer
        
                if (self.isHorizontal) {
                    //gradientLayer.colors = [firstColor, secondColor, thirdColor].map{$0.cgColor}
        
                    gradientLayer.colors = [firstColor.withAlphaComponent(1.0), secondColor.withAlphaComponent(0.59), thirdColor.withAlphaComponent(1.0)].map{$0.cgColor}
                    gradientLayer.locations = [0.29, 0.60, 1]
                    gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5)
                    gradientLayer.endPoint = CGPoint (x: 1.0, y: 0.5)
                } else {
                    gradientLayer.colors = [firstColor.withAlphaComponent(0.5), secondColor.withAlphaComponent(0.0), thirdColor.withAlphaComponent(0.0)].map{$0.cgColor}
                    gradientLayer.startPoint = CGPoint(x: 0.5, y: 1.0)
                    gradientLayer.endPoint = CGPoint (x: 0.5, y: 0.5)
                }
            }
        }
        

        【讨论】:

        • 如果 durationLabel 是自定义 UITableViewCell 的一部分,您能否更新您的代码?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-25
        • 2013-11-01
        • 2010-12-01
        • 2010-12-27
        • 1970-01-01
        • 2011-08-23
        相关资源
        最近更新 更多