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

How to make radial gradient to be faded in the middle of view in Objective C

I want to make radial gradient view as above attached image but I am not able to make fade in the middle, here is my code for gradient. CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = view_background.bounds; gradient.colors =…
Jack
  • 68
  • 1
  • 6
3
votes
2 answers

Adding a sublayer to a UIView (background view) of UITableViewCell covers other cell views?

I'm trying to add a gradient to a UIView that serves as a background (backgroundRect) of a UITableViewCell. I expected the gradient to be drawn at the same Z position as the backgroundRect, however when building on device it obscures (over top of)…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
3
votes
2 answers

How to create Gradient border with rounded corners at UIView in Swift 4

I want to set border color with the gradient left to right [Red, Green] at UIView. Like example: I tried below code: - class View: UIView { override func layoutSubviews() { super.layoutSubviews() let path =…
Asif Raza
  • 836
  • 12
  • 29
3
votes
1 answer

iOS UISLider with gradient layer

I'm building an iOS application in which I have to implement a custom UISlider. The problem is that the built-in UISlider doesn't support gradient track. Another issue is my UI style guide shows that the current tracking value rectangle should be a…
AouledIssa
  • 2,528
  • 2
  • 22
  • 39
3
votes
2 answers

How can I add a gradient that spans two views?

I know how to do (1) but how can I do (2)? UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = view.bounds; gradient.colors = @[(id)[UIColor…
Vulkan
  • 1,004
  • 16
  • 44
3
votes
1 answer

How to draw a gradient color wheel using CAGradientLayer?

I got some reference from these links- What is the Algorithm behind a color wheel? Math behind the Colour Wheel Basic color schemes How to fill a bezier path with gradient color I have gone through the concept of "HSV colour space". But I want to…
Amir Khan
  • 1,318
  • 1
  • 14
  • 39
3
votes
1 answer

CAGradient layer not visible on view

I try to add a CAGradient effect in a pie chart I make with Core Graphics. It turns out I am not able and certainly not understand very well how to apply it to a view that is part of a CGPath... override func draw(_ rect: CGRect) { ... …
Trichophyton
  • 625
  • 5
  • 21
3
votes
3 answers

How to add a CAGradientLayer to a UIView when using programmatic constraints

For an iOS app in Swift, I am using programmatic constraints and would like to add a CAGradientLayer() to a UIView(). Below is my code which doesn't work. import UIKit class ViewController: UIViewController { let animationView: UIView…
Edward
  • 2,864
  • 2
  • 29
  • 39
3
votes
1 answer

CAGradientLayer color change animation not executing

I'm trying to get a very basic CAGradientLayer animation to work. I have a basic 2 color CAGradientLayer set up and added to my UIViewController. // Set up the gradient layer. var gradientLayer: CAGradientLayer! { let layer = CAGradientLayer() …
Sam Fischer
  • 1,442
  • 19
  • 35
3
votes
0 answers

Draw 3/4 of a circle with gradient of three colors

I want to draw 3/4 of a circle with a gradient border, like this: I can draw this circle with this code: func createProgressLayer() { let startAngle = CGFloat(M_PI_2) let endAngle = CGFloat(M_PI * 2 ) let centerPoint =…
Tejas Ardeshna
  • 4,343
  • 2
  • 20
  • 39
3
votes
1 answer

Static Gradient Image vs CAGradientLayer?

I need to show some gradient background in the app, so far there are two options in my mind, one is to use static gradient images, the other one is to use CAGradientLayer, and I'm struggling to choose between them. I only need to have three colour…
Heuristic
  • 5,087
  • 9
  • 54
  • 94
3
votes
2 answers

CAGradientLayer causes subviews not being visible

Hello Masters of iOS and Swift, after two frustrating days, I desperately decided to ask here. The problem: When adding a CAGradientLayer, the subviews aren't shown. Details: I have made a method to add a CAGradientLayer in an extension of UIView I…
LukeSideWalker
  • 7,399
  • 2
  • 37
  • 45
3
votes
2 answers

How to set UICollectionView layer not moving/static while scrolling Swift

I added a gradient layer to UICollectionView, but the layer is set to the width of the screen. I am trying to keep the layer static while scrolling but can't find a solution. Tried setting to both the frame of the collectionView and to the…
Tal Zion
  • 6,308
  • 3
  • 50
  • 73
3
votes
0 answers

How to lightly fade bottom of UIImage and Fade to Blur as scrolling up

I've been working on a UICollectionView header as a UICollectionReusableView and I'm trying to achieve 1) a lightly bottom faded image and 2) as the user scrolled up the image would blur. I'm essentially looking at Apple's Music app, and it's an…
chinjazz
  • 135
  • 1
  • 2
  • 13
3
votes
1 answer

How to draw Arc with curved edge in iOS?

In one of my application, I am trying to draw a gradient arc with rounded edges. Like the following image. This is what I have done so far using the following code. -(void)startArc { UIBezierPath *roundedArc = [self…
Bharath
  • 3,001
  • 6
  • 32
  • 65