Add gradient in iOS
Suppose you want to add the multicolor view in your application in the background, for this you have to set the gradient in background view. Firstly, you have to add the gradient on UIView then you have to add the UIImageView and add the image to the UIImageView then make that UIImageView transparent mean you have set the alpha of UIImageView (image.alpha = 0.1). Example using gradient:-
1 2 3 4 5 6 7 8 9 10 |
let bounds = UIScreen.main.bounds let height = bounds.size.height let gradient: CAGradientLayer = CAGradientLayer() gradient.frame = CGRect(x :0, y: CGFloat(0), width : SCREEN_WIDTH, height : height/2) gradient.colors = [UIColor().HexToColor(hexString: "1d7ad8").withAlphaComponent(1.0).cgColor ,UIColor.green.withAlphaComponent(0.5).cgColor ] myView .layer.addSublayer(gradient) self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width / 2; self.profileImageView.clipsToBounds = true backgroundImage.alpha = 0.1 |