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

Swift: rainbow colour circle

Hi i am trying to write colour picker in swift that looks like this. But so far I managed this. Draw circle was easy, heres code... fileprivate func setupScene(){ let circlePath: UIBezierPath = UIBezierPath(arcCenter: CGPoint(x:…
Pan Mluvčí
  • 1,242
  • 2
  • 21
  • 42
4
votes
1 answer

Gradient at Top/Bot of Scrollview When There's Additional Content

I have a scrollview>ContentView>TextLabel setup where the gradient is showing up but not working how I want it to. It's a clear background scrollView, so all I'm looking for is a clear gradient mask over the text. I found something similar to I'm…
Dave G
  • 12,042
  • 7
  • 57
  • 83
4
votes
1 answer

Draw transparent-to-white gradient over white in iOS

I have an iOS app with text on the main screen that scrolls. I want the text to fade out at the bottom of the screen. So I make a custom view and do something like this in drawRect: CGColorSpaceRef colorSpace =…
Tom Hamming
  • 10,577
  • 11
  • 71
  • 145
4
votes
1 answer

UIView with CAShapeLayer does not display CAGradientLayer

I try to apply a radiant to a custom shaped UIView The gradiant category I used if well tested and used in other part of my code. However, I cannot get it to function properly in a custom shaped view created using a CAShapeLayer In my UIView…
Antzi
  • 12,831
  • 7
  • 48
  • 74
4
votes
3 answers

CAGradientLayer radial gradient

I used the following code to set gradient color: NSArray *locations = @[@0.0, @0.1f]; CAGradientLayer *headerLayer = [CAGradientLayer layer]; headerLayer.colors = colors; headerLayer.locations = locations; How can I make radial gradient color? I…
Mariam
  • 683
  • 1
  • 11
  • 27
4
votes
2 answers

How to change color of CAGradientLayer like screensaver?

I was created UIView with applying CAGradientLayer color effect as i attached Image Bellow. Now in this i want to change it's gradient color change top to bottom side smoothly like screensaver. I have Been tried using NStimer that bit Done but its…
Bhavesh Lakum
  • 130
  • 1
  • 12
4
votes
1 answer

CAGradientLayer with Angle

I am drawing CGPath which is not rectangle or square,and adding CGPath to CAShapeLayer. This CAShapeLayer's frame getting from CGPath using CGPathGetBoundingBox(path). So it will be rectangle or square. Now i want to set gradient color to layer but…
h999
  • 395
  • 1
  • 5
  • 21
4
votes
1 answer

UILabel add GradientLayer

To add a background gradient to a UILabel I use the following code. Before using the gradient, UILabel Appears like this. Now, to add a gradient I use the following code. CAGradientLayer *gradLayer=[CAGradientLayer layer]; …
weber67
  • 525
  • 1
  • 9
  • 18
4
votes
1 answer

Draw CAGradient within MKPolyLineView

i have just a problem with my MKPolyLineView. I simply try to make a color gradient to the Polyline, but with CAGradient it doenst work. I subclasses MKPolylineView and redrawing in - (void)drawMapRect:(MKMapRect)mapRect…
Fry
  • 922
  • 2
  • 10
  • 24
4
votes
1 answer

How to Create a UIButton with Gradient and Highlighting?

I am trying to create a UIButton with a gradient background. I got that work fine but the button does not highlight (default behavior is for the button to darken) when selected. here's my button: -(UIButton *)createLoginButtonForSize:(CGSize)size { …
Padin215
  • 7,444
  • 13
  • 65
  • 103
4
votes
1 answer

Applying CAGradient mask layer to UITextView

I've got a UITextView, with scrollable text. I'm trying to apply a gradient layer to it, so the bottom of the visible text is always slightly faded out. Here's my code: CAGradientLayer *maskLayer = [CAGradientLayer layer]; maskLayer.colors =…
Mike Stein
  • 227
  • 4
  • 8
3
votes
3 answers

UIView with gradient not changing colors when button is tapped

When a user clicks on a button, it randomizes the colors used to create a gradient in a large circle. Beneath it are two small circles that display the solid colors used for the gradient. They all display correctly at the start (main circle is a…
3
votes
1 answer

Swift not calling class init method on CAGradientLayer

I have an Objective-C subclass of 'CAGradientLayer' that overrides the '+ (CAGradientLayer *)layer' initializer. It is correctly included in my Bridging-Header #import "ONCGradientLayer.h" @implementation ONCGradientLayer + (ONCGradientLayer…
olynoise
  • 2,016
  • 2
  • 19
  • 32
3
votes
2 answers

Radial CAGradientLayer not rendering properly at runtime

I'm trying to create a radial CAGradientLayer in swift. Normal CAGradientLayers (with default type axial) are no problem. They are rendering fine on the snapshot and on runtime in the simulator. When I take a snapshot of the UIView that I created…
Charlotte1993
  • 589
  • 4
  • 27
3
votes
2 answers

How to make a gradient circular path in Swift

I want to create a gradient circular path like the following image: and I have the following code: circularPath = UIBezierPath(arcCenter: .zero, radius: radius, startAngle: 0, endAngle: .pi * 2, clockwise: true) outerTrackShapeLayer =…
Mehdi Mirzaei
  • 376
  • 3
  • 13