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
0
votes
3 answers

Add Gradient on a view in Swift

The following code seems to work using Objective-C however its Swift version doesn't work. I have tried the following: Add the gradient inside the collection view cell Add the gradient in the viewController Use UIColor & CGColor Use…
Ehmad Zubair
  • 215
  • 3
  • 10
0
votes
1 answer

Gradiant in playground different from simulator

I tried to make a gradiant using playground then make it into a subclass of uiview to use it in my codebase. The playground code is like this: let view = UIView(frame: CGRect(x: 0, y: 0, width: 640, height: 41 )) let gradient: CAGradientLayer…
Antzi
  • 12,831
  • 7
  • 48
  • 74
0
votes
2 answers

CAGradientLayer of UIView in TableView not resizing to Autolayout

I have created a UIView in IB with tag: 6. I use it in tableView. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell:UITableViewCell =…
KML
  • 2,302
  • 5
  • 26
  • 47
0
votes
1 answer

Draw line on UIView with CAGradientLayer as backing store

I have created a UIView subclass which uses a CAGradientLayer for its layer. This is working fine. Now I want to draw a line at the end of the gradient (used as separator). I thought I can use the drawRect method for this: public class GradientView…
testing
  • 19,681
  • 50
  • 236
  • 417
0
votes
1 answer

Rotation background gradient xcode

I have a problem with my background gradient on my app. I set in viewDidLoad in MainViewController. CAGradientLayer *bgLayer = [BackgroundGradient blackGradient]; bgLayer.frame = self.view.bounds; [self.view.layer insertSublayer:bgLayer…
Patrik Dendis
  • 313
  • 6
  • 20
0
votes
1 answer

Circular gradient color "Not linear" in UIView

I have an issue with the gradient color, I'm not able to make the gradient color appear as circular, it always appear like linear, i need the exact gradient in the following image: PS: this is the code i use: UIView *view = [[UIView alloc]…
Mutawe
  • 6,464
  • 3
  • 47
  • 90
0
votes
2 answers

CAGradientLayer in UITableViewCell

I have a UITableViewCell that has an UIView (gradientView) where I want to apply the gradient. This cell has AutoLayout, and so I want to update the gradient frame when the gradientView frame changes. I have tried the following, but none of them…
rob180
  • 901
  • 1
  • 9
  • 29
0
votes
1 answer

Draw order using CAGradientLayer & drawRect:(CGRect)

My view overrides the drawRect method to render graphics. And I've recently added a gradient background using CAGradientLayer and [view.layer insertSubLayer: atIndex:0] However the CAGradientLayer gets drawn over my graphics instead of…
0
votes
1 answer

CAGradientLayer, not resizing nicely, tearing on rotation SWIFT

So I'm working on a iOS application written in Swift and I came across this exact same issue as this: CAGradientLayer not resizing nicely. I add a CAGradientLayer to my UIView and I override willAnimateRotationToInterfaceOrientation in order to…
Mario A Guzman
  • 3,483
  • 4
  • 27
  • 36
0
votes
1 answer

Swift playground image doesn't show what it should

I got the following code that I run in XCode playground: let initalFrame = CGRect(x:0,y:0,width:10,height:10) let myLabel = UILabel(frame: CGRectMake(0,0,50,50)) myLabel.backgroundColor =…
0
votes
4 answers

How to increase the color space CAGradientLayer

I have a Gradient that has three colors, Black, clear, and black. How would you increase the middle section? The desired effect I am going for is a shading/gradient at the top, clear middle show content can show clearly, and a shading/gradient at…
DevC
  • 6,982
  • 9
  • 45
  • 80
0
votes
1 answer

iOS gradient animating with uiscrollview paging

I have an horizontal scrollview with 3 pages. I would like to have one background color different for each page and draw gradient between the 3 colors. Page 1 with green, page 2 with blue and page 3 with red. How can I do that? I was thinking about…
Tenaciousd93
  • 3,438
  • 4
  • 33
  • 56
0
votes
3 answers

Swift: gradient on a cell of a tableview

On tableView's cells, I'm trying to define a gradient with the following Swift code: func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { var cell:UITableViewCell =…
0
votes
1 answer

CAGradientLayer doesn't work on UITableView backgroundColor

I'd like to have gradient background color behind of a table view, which has transparent navigation bar. Codes as following, but gradient color doesn't show up. Tried code part of CAGradientLayer in a simple normal UIViewController, it does…
S1U
  • 825
  • 2
  • 14
  • 26
0
votes
2 answers

Gradient in UITableViewCell Appearing Over Content

I am trying to add a gradient to the background of a custom cell, and when I display the gradient using addSublayer it shows over the rest of the content, and when I use insertSublayer: atIndex: 0 it doesn't appear. This cell is a custom cell, what…
trumpeter201
  • 8,487
  • 3
  • 18
  • 24