渐变未覆盖全帧 SWIFT [英] Gradient not covering full frame SWIFT
本文介绍了渐变未覆盖全帧 SWIFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 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 时,我有以下输出.我尝试设置约束以及自动布局.
on applying this to the imageView, I am having the following output. I tried setting the constraints and also, the autolayout.
以下是执行后的输出:
推荐答案
需要致电
imageView.addBlackGradientLayer(frame: imageView.bounds)
参见:Cocoa:框架和边界?
这篇关于渐变未覆盖全帧 SWIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文