Questions tagged [cagradientlayer]

`CAGradientLayer` is a special purpose `CALayer` subclass for drawing animatable linear gradients. It's a part of the QuartzCore framework and is available for both iOS (since iOS 3.0) and OS X (since OS X v10.6 "Snow Leopard"). The gradient is specified using four properties for the `colors`, their `locations` and the `startPoint` and `endPoint` of the layer. All four properties are animatable.

CAGradientLayer is a special purpose CALayer subclass for drawing animatable linear gradients. It's a part of the framework and is available for both (since iOS 3.0) and (since OS X v10.6 "Snow Leopard").

The gradient is specified using four properties for the colors, their locations and the startPoint and endPoint of the layer. All four properties are animatable.

The colors is an NSArray of CGColorRef objects therefore they need to be cast to ids when adding them to the array.

The locations, startPoint and endPoint are specified in the unit coordinate space of the layers bounds. This means that the values go from 1.0 to 0.0. In both iOS and OS X, x increases to the right which means that 0.0 is the left edge and 1.0 is the right edge. On iOS y increases downward and on OS X y increases upwards.

405 questions
14
votes
1 answer

Swift 2.1: CAGradientLayer color location & distribution

My need is to show 3-colored distribution in a view. So I'm using following code. func drawWithGradientLayer() { // total contains sum of all values contained in segmentValues variable. // I'm using green -> Orange -> Red colors as…
Abid Hussain
  • 1,529
  • 1
  • 15
  • 33
13
votes
2 answers

CAGradientLayer properties not animating within UIView animation block

I have a feeling I'm overlooking something elementary, but what better way to find it than to be wrong on the internet? I have a fairly basic UI. The view for my UIViewController is a subclass whose +layerClass is CAGradientLayer. Depending on the…
Sixten Otto
  • 14,816
  • 3
  • 48
  • 60
13
votes
3 answers

Objective C - CAGradientLayer covers the text in UILabel?

I am trying to add a gradient layet to my UILabel for some reasons the CAGradientLayer covers my text. Am I doing anything wrong - (void)viewDidLoad { [super viewDidLoad]; CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
13
votes
4 answers

background Gradient : linear left to right in objective C

My client wants the background View with this gradient effect background Gradient : rgb(118,118,118) | #ffffff | rgb(198,198,197) linear left to right I have tried this way but it is happening in Vertical direction I want it in Horizontal…
Harshit Goel
  • 679
  • 1
  • 6
  • 20
13
votes
3 answers

iOS UIProgressView with gradient

is it possible to create a custom ui progress view with a gradient from left to right? I've tried it with the following code: let gradientLayer = CAGradientLayer() gradientLayer.frame = self.frame gradientLayer.anchorPoint = CGPoint(x:…
user3532505
  • 429
  • 1
  • 7
  • 18
12
votes
5 answers

Angled Gradient Layer

I have custom UIView class that renders a gradient in Swift 2. I'm struggling with making an angled gradient so that it draws from the top-left to the bottom-right. Can somebody help me a bit? import UIKit class GradientView: UIView { let…
Kira
  • 1,575
  • 4
  • 26
  • 48
12
votes
1 answer

CAGradientLayer not working

I created a new project. I linked QuartzCore.framework and imported in the ViewController.m. And here is the code. - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"view height %f", self.view.frame.size.height);…
SFF
  • 877
  • 2
  • 11
  • 26
11
votes
1 answer

Swift gradient from black to fully transparent

I am trying to apply a CAGradientLayer using swift, and I would like it to fade from black to transparent. I thought putting any color with an alpha: 0 would render the same "transparent" color. It is not the case. White with alpha: 0 is still a bit…
Scaraux
  • 3,841
  • 4
  • 40
  • 80
10
votes
6 answers

Add a gradient on UIImageView

I am trying to add a sublayer on my UIImageView but it doesn't work. I have a set of 10 images named from photo0 to photo9 and I display it with a timer of 5s. The outlet shanghaiImage is my background I would like to add a gradient on top of…
Alexandre
  • 161
  • 1
  • 1
  • 10
9
votes
3 answers

iOS fade to black at top of UIImageView

I have a UITableView where my cell backgroundView is a UIImageView. I would like top of each image to fade to black so I can overlay some white text. I have looked at some answers like this, but none seem to be working. In tableView(tableView:…
Imran
  • 12,950
  • 8
  • 64
  • 79
8
votes
3 answers

How to update CAGradientLayer colors on runtime in iOS swift?

I am using a UIView extension for applying a gradient layer to a UIView. I need to change the gradient colors on runtime while scrolling a tableview. I use the scrollview contentoffset value to update the gradient color. What I tried: I tried to…
abhimuralidharan
  • 5,752
  • 5
  • 46
  • 70
8
votes
1 answer

Drawing gradient using CAGradientLayer on UIView not working

I'm trying to draw a gradient on the background view of a View Controller with but for some reason I couldn't get it to work. Here is my method, which is called from viewDidLoad: - (void)drawGradient { CAGradientLayer *gradient = [CAGradientLayer…
WedgeSparda
  • 1,161
  • 1
  • 15
  • 40
8
votes
2 answers

Using CAGradientLayer for an angle / circle gradient

How can I use a CAGradientLayer to most efficiently draw a gradient around a circle / with angles? I made the one underneath with the help of this project. It uses a bitmap context for drawing but a CAGradientLayer would be far more efficient.…
Max
  • 2,699
  • 2
  • 27
  • 50
8
votes
2 answers

Filling a path with a gradient on iOS

On a CAShapeLayer, I've drawn a closed UIBezierPath. I can fill this shape by setting the fillColor, however I want to fill the shape with a gradient. How can I set up the CAGradientLayerso it clips to the shape outlined by the bezier path?
Thorsten
  • 12,921
  • 17
  • 60
  • 79
7
votes
2 answers

Right way to reproduce sketch gradient with CAGradientLayer

I would like to create a gradient layer with four given colours. I have a sketch file for the gradients. I have the coordinates for the colour stops. I calculated the normalised coordinates for the start and the end point for the CAGradientLayer. I…
Gergely
  • 448
  • 3
  • 13
1
2
3
26 27