我有一个非常基本的UICollectionView。在我的CollectionViewCell中,我有一个" thumbnailImage"这只是一个图像。我希望有一个从黑色渐变到渐变色的渐变层,但我也希望这个CAGradient的UILabel ON TOP 而不是下面。标签是" MovieTitle"。我以编程方式执行所有操作,包括约束。我该怎么做?这是我的代码
let myView: UIView = {
let view = UIView()
return view
}()
let gradientView: CAGradientLayer = {
let grad = CAGradientLayer()
grad.colors = [UIColor.white.cgColor, UIColor.red.cgColor]
grad.locations = [0.7, 1.2]
return grad
}()
func setupViews() {
thumbnailImageView.addSubview(movieTitle)
addSubview(thumbnailImageView)
thumbnailImageView.addSubview(dividerLine)
thumbnailImageView.addSubview(myView)
myView.layer.addSublayer(gradientView)
addConstrainsWithFormat(format: "H:|[v0]|", views: thumbnailImageView)
addConstrainsWithFormat(format: "V:|[v0]|", views: thumbnailImageView)
thumbnailImageView.addConstrainsWithFormat(format: "H:|[v0]|", views: myView)
thumbnailImageView.addConstrainsWithFormat(format: "V:|[v0]|", views: myView)
thumbnailImageView.addConstrainsWithFormat(format: "H:|[v0]|", views: dividerLine)
thumbnailImageView.addConstrainsWithFormat(format: "V:[v0(0.75)]|", views: dividerLine)
thumbnailImageView.addConstrainsWithFormat(format: "H:|-16-[v0]-16-|", views: movieTitle)
thumbnailImageView.addConstrainsWithFormat(format: "V:[v0(25)]-8-|", views: movieTitle)
}
答案 0 :(得分:0)
尝试更改视图的顺序,以便标签显示在视图上方,其中包含渐变:
With ws
.Unprotect Password:="password"
.Cells(iRow, 1).Value = Me.Textbox1.Value
.Cells(iRow, 1).Value = Me.time.Value
.Cells(iRow, 2).Value = Me.card.Value
.Cells(iRow, 1).Value = Me.nature.Value
.Cells(iRow, 2).Value = Me.ma.Value
.Cells(iRow, 1).Value = Me.mem1.Value
.Cells(iRow, 2).Value = Me.mem2.Value
.Cells(iRow, 3).Value = Me.mem3.Value
.Cells(iRow, 4).Value = Me.mem4.Value
.Cells(iRow, 5).Value = Me.mem5.Value
.Cells(iRow, 6).Value = Me.mem6.Value
.Cells(iRow, 7).Value = Me.mem7.Value
.Cells(iRow, 8).Value = Me.mem8.Value
.Cells(iRow, 9).Value = Me.mem9.Value
.Cells(iRow, 10).Value = Me.mem10.Value
.Protect Password:="password"
End With
您还可以在层次结构中现有图层/视图的下方或上方插入图层和视图:
myView.layer.addSublayer(gradientView)
thumbnailImageView.addSubview(myView)
thumbnailImageView.addSubview(movieTitle)
thumbnailImageView.addSubview(dividerLine)
addSubview(thumbnailImageView)