gpt4 book ai didi

ios - 渐变不覆盖全帧 SWIFT

转载 作者:行者123 更新时间:2023-11-29 00:10:00 26 4
gpt4 key购买 nike

我有以下 imageView 扩展:

extension UIImageView {
func addBlackGradientLayer(frame: CGRect){
let gradient = CAGradientLayer()
gradient.frame = frame
gradient.colors = [UIColor.clear.cgColor, UIColor.black.cgColor]
gradient.locations = [0.0, 1.0]
self.layer.addSublayer(gradient)
}}

imageView.addBlackGradientLayer(frame: imageView.frame)

将其应用于 imageView 时,我得到以下输出。我尝试设置约束以及自动布局。

执行后的输出如下:

enter image description here

最佳答案

你需要打电话

imageView.addBlackGradientLayer(frame: imageView.bounds)

参见:Cocoa: What's the difference between the frame and the bounds?

关于ios - 渐变不覆盖全帧 SWIFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46753710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com