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
231
votes
30 answers

How to Apply Gradient to background view of iOS Swift App

I'm trying to apply a gradient as the background color of a View (main view of a storyboard). The code runs, but nothing changes. I'm using xCode Beta 2 and Swift. Here's the code: class Colors { let colorTop = UIColor(red: 192.0/255.0, green:…
justingordon
  • 12,553
  • 12
  • 72
  • 116
94
votes
7 answers

iOS White to Transparent Gradient Layer is Gray

I have a CAGradientLayer inserted to the bottom of this small detail view that pops up at the bottom of the app. As you can see, I've set the colors from white to clear, but there's this strange gray tint that is showing up. Any ideas? // Set up…
Eric Gao
  • 3,502
  • 2
  • 19
  • 29
69
votes
10 answers

CAGradientLayer, not resizing nicely, tearing on rotation

I'm trying to get my CAGradientLayers, that i'm using to create nice gradient backgrounds, to resize nicely on rotation and modal view presentation, but they will not play ball. Here is a video I just created showing my problem: Notice the tearing…
Woodstock
  • 22,184
  • 15
  • 80
  • 118
40
votes
5 answers

UIView transparent gradient

Given an arbitrary UIView on iOS, is there a way using Core Graphics (CAGradientLayer comes to mind) to apply a "foreground-transparent" gradient to it? I can't use a standard CAGradientLayer because the background is more complex than a UIColor. I…
jpsim
  • 14,329
  • 6
  • 51
  • 68
35
votes
1 answer

How to change CAGradientLayer color points?

Right now I've got a GA Gradient layer where I've set the colors but I'd like to set the color point to (instead of top center, to top left) and the bottom to (instead of bottom center to bottom right) just to change things up a bit. Thoughts? Below…
user1940321
34
votes
4 answers

UIButton with GradientLayer obscures image and darkens gradient

I have an UIButton here where I'd like to have a gradient as the background below the image (symbol with transparent background), but I'm facing two different problems. First of the CAGradientLayer seems to overlay on top of the image no matter how…
Christian A. Strømmen
  • 3,181
  • 2
  • 25
  • 46
28
votes
3 answers

CAGradientLayer diagonal gradient

I use the following CAGradientLayer: let layer = CAGradientLayer() layer.colors = [ UIColor.redColor().CGColor, UIColor.greenColor().CGColor, UIColor.blueColor().CGColor ] layer.startPoint = CGPointMake(0, 1) layer.endPoint =…
Evgeny
  • 631
  • 6
  • 17
25
votes
3 answers

horizontal CAGradientLayer in iOS 7.0

Inside my application I use a CAGradientLayer to set the background of my cell, in this way: retValue = [tableView dequeueReusableCellWithIdentifier:@"Cells" forIndexPath:indexPath]; UIView *bgColorView = [[UIView alloc]…
Perry
  • 1,113
  • 2
  • 10
  • 22
24
votes
3 answers

Fade out scrolling UITextView over image?

I’m looking to fade out a scrolling UITextView over a background image, something similar to the gradient at the top of this little example. I’m trying to work out how I can achieve this using CAGradientLayer and masks. As the text in the view…
Luke
  • 9,512
  • 15
  • 82
  • 146
21
votes
1 answer

How to apply CAGradientLayer as mask of another CALayer?

I have a view, which has a CALayer. When I create a CAGradientLayer and apply it as the mask of that view's CALayer, nothing happens. Why? In -initWithFrame: of the view I do this: CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame…
Proud Member
  • 40,078
  • 47
  • 146
  • 231
20
votes
1 answer

How to give "locations" to CAGradientLayer

I have created CAGradientLayer having three colors, i need to give each color different locations. Example: Red = 0 to 50 % Yellow = 51 to 80 % Green = 81 to 100 % I have tried with giving startPoint and endPoint but it did not work.
Sunil Rao
  • 800
  • 2
  • 6
  • 23
16
votes
3 answers

Defining angle of the gradient using CAGradientLayer

I am trying to draw angular gradient using CaGradientLayer. I know angle can be defined using startPoint and endPoint. I can compute these points for some standard angles like 0, 90, 180, 360 etc. But I want formulate these points for arbitrary…
blancos
  • 1,576
  • 2
  • 16
  • 38
16
votes
2 answers

How to resize a CAGradientLayer after rotation?

I'm adding a CAGradientLayer to a view. When the view is auto-resized (such as after a rotation) the gradient layer is not resized. Can the gradient be set to auto-resize the same as the view? Note also that I am using auto-layout constraints in the…
memmons
  • 40,222
  • 21
  • 149
  • 183
15
votes
3 answers

CAGradientLayer send to back

I have a UIViewController where I create a background gradient with CAGradientLayer *gradient = [CAGradientLayer layer]; ... gradient.frame = frame; self.backGradient = gradient; [self.view.layer insertSublayer:gradient…
AlexWien
  • 28,470
  • 6
  • 53
  • 83
14
votes
4 answers

Applying gradient background for UIView using auto layout

I extended UIView to add a addGradientWithColor() method to get the gradient background: extension UIView { func addGradientWithColor() { let gradient = CAGradientLayer() gradient.frame = self.bounds gradient.colors =…
Aravind
  • 1,080
  • 2
  • 12
  • 18
1
2 3
26 27