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
7
votes
1 answer

Drawing A Circle With Gradient Stroke

I am working on a task in which I must create a circle with no fill, but a gradient stroke. For reference, here is the end result I am after; Given other occurrences with the app, I am drawing my circle like so; let c =…
ZbadhabitZ
  • 2,753
  • 1
  • 25
  • 45
7
votes
2 answers

Apply gradient on a UIView not working

I am trying to add gradient to a UIView programmatically but it is not working. It just appears to have no color at all. I have attached the relevant code as well as a screenshot. Notice the bottom square over which i am applying the gradient. Can…
Ryan Cyrus
  • 309
  • 5
  • 14
7
votes
1 answer

set horizontal gradient in UITableviewcell swift

I want to create a horizontal gradient from left to right on each cell I use CAGradientLayey to create a custom layer and add this layer to tableview cell This is my code in swift func gradient(frame:CGRect) -> CAGradientLayer { let layer =…
sin90
  • 171
  • 1
  • 12
7
votes
3 answers

Button background and gradient change since iOS6

For an app I had to create a UIButton filled with a gradient and a background image. Everything worked fine until I upgraded the OS from iOS 5.1 to the recently released iOS 6. Here are two screenshots from the simulator : Well, the first…
Edelweiss
  • 621
  • 1
  • 9
  • 24
6
votes
1 answer

Applying gradient layer over a UIBezierPath graph

This is my first time asking a question, so pardon me if it not very thorough. Basically I am trying to apply a gradient layer on top of a UIBezierPath that is drawn as a graph. Here is my graph: Here is the gradient layer I am going for: Here…
6
votes
2 answers

Adding gradient layer to tableview

I have been trying to figure out for quite a while now about how to add a gradient layer to the tableView, and have tried many different things, but I can never get the table view cells to show, no matter how many bringSubviews or sendSubviews I…
D-A UK
  • 1,084
  • 2
  • 11
  • 24
6
votes
1 answer

Animate a layer property which simply changes other properties?

Imagine a CAGradientLayer. It's very easy to animate .startPoint and .endPoint. Now imagine a float spinLike which simply sets both of them at once. {So, instead of having two different animations, you could simply animate spinLike.} So something…
Fattie
  • 27,874
  • 70
  • 431
  • 719
6
votes
3 answers

iOS UITableView: assign background color as gradient using CAGradientLayer

I just started playing with the Master-Detail view template in Xcode 4.3 and I am trying to change the background color of master and set it to a color gradient. Here is what I tried: Colors.m #import "Colors.h" @implementation Colors + (UIColor…
vikmalhotra
  • 9,981
  • 20
  • 97
  • 137
5
votes
3 answers

CAGradientLayer does not display

I have looked over a bunch of other answers to questions like this, but none of the answers seem to solve my problem, so looking for a little help. I'm trying to apply a vertical gradient to a UIButton, but the gradient layer is just not showing up…
kyanring
  • 95
  • 1
  • 6
5
votes
2 answers

Why gradient layer in UITableViewCell not cover entire frame?

I try to make a standard gradient top-bottom with long UIView. But it's not full. The nib is part of UITableViewCell, so I don't have access to viewDidLayoutSubviews() as in this thread. I've tried to call contentView.layoutIfNeeded() from the…
Seto
  • 1,234
  • 1
  • 17
  • 33
5
votes
1 answer

Adding a mask to CAGradientLayer makes UIBezierPath disappear

I want to add an inner border to a view with a gradient. The following code works and gives me this result import UIKit class InnerGradientBorderView: UIView { override init(frame: CGRect) { super.init(frame: frame) …
Zia
  • 14,622
  • 7
  • 40
  • 59
5
votes
2 answers

How to remove CAGradientLayer from it's super layer

I add the layer to my view: [self.layer insertSublayer:_gradient above:_another.layer]; Then it doesn't seem to get removed with this, even if I call needsDisplay on the super layer: [_gradient removeFromSuperlayer]; How can I remove…
kev
  • 7,712
  • 11
  • 30
  • 41
4
votes
4 answers

iOS 12 Photos App video thumbnail label gradient issue

The Photo Library on iOS 12 puts some kind of tricky gradient background on the thumbnail to display video duration label. I recorded a pure white background video and the label has a white to black gradient. But on other thumbnails, the gradient is…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
4
votes
1 answer

CAGradientLayer overflows on UIView when using in UITableViewCell

I've add CAGradientLayer to a UIView that've already inside in UITableViewCell. This UIView has 20 trailing and leading space from the UITableViewCell contentView. But that UIView's overflow when it running. var gradientLayer:…
eemrah
  • 1,603
  • 3
  • 19
  • 37
4
votes
1 answer

Gradient does not fill all the UIView

I want to create a gradient layer and insert it in a view but the view is not fully filled... My actual code is : gradientLayer.frame = topView.bounds gradientLayer.colors = [UIColor.white.cgColor, UIColor.black.cgColor] …
Psyycker
  • 317
  • 4
  • 16
1 2
3
26 27