Mohammed Alessi
Mohammed Alessi

Reputation: 13

CALayer Hides the UILabel above the UIView

I have a UIView with a CAGradientLayer, but the labels in the UIView don't appear when i launch the app.

@IBOutlet weak var CardView: UIView!
@IBOutlet weak var CardTiltle: UILabel!
@IBOutlet weak var CardInfo: UILabel!

func prepareCardViewUI() {

    let GradientLayer = CAGradientLayer()
    GradientLayer.frame = CardView.bounds
    GradientLayer.colors = [UIColor(red: 254/255, green: 164/255, blue: 156/255, alpha: 1).cgColor, UIColor(red: 252/255, green: 207/255, blue: 170/255, alpha: 1).cgColor]
    GradientLayer.startPoint = CGPoint(x: 1.0, y: 0.0)
    GradientLayer.endPoint = CGPoint(x: 0, y: 1.0)
    GradientLayer.cornerRadius = 25


    CardView.layer.addSublayer(GradientLayer)
    CardView.layer.cornerRadius = 25
}

Upvotes: 1

Views: 79

Answers (1)

iVarun
iVarun

Reputation: 6611

Change this line CardView.layer.addSublayer(GradientLayer) with below line:

CardView.layer.insertSublayer(GradientLayer, at: 0)

Hope this will work for you.

enter image description here

Upvotes: 4

Related Questions