问题描述
我正在尝试向UIImageView添加渐变。
viewDidLoad() {
self.bookImageBig.sd_setImage(with: URL(string: self.book.image),placeholderImage: nil)
self.bookImage.sd_setImage(with: URL(string: self.book.image),placeholderImage: nil)
let view = UIView(frame: bookImageBig.frame)
let gradient = CAGradientLayer()
gradient.frame = view.frame
gradient.colors = [UIColor.clear.cgColor,UIColor.black.cgColor]
gradient.locations = [0.0,1.0]
view.layer.insertSublayer(gradient,at: 0)
bookImageBig.addSubview(view)
bookImageBig.bringSubviewToFront(view)
我正在尝试为bookImageBig UIImageView添加渐变。
但是,渐变仅部分覆盖了图像。渐变不覆盖图像的30px。该图像已添加到故事板上,并在视图控制器中被引用。 有人可以帮忙吗?