cagradientlayer

UILabel add GradientLayer [duplicate]

喜你入骨 提交于 2019-12-01 07:19:33
问题 This question already has answers here : Adding a CGGradient as sublayer to UILabel hides the text of label (4 answers) Closed 6 years ago . 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]; gradLayer.frame=self.myView.layer.bounds; [gradLayer setColors:[NSArray arrayWithObjects:(id)([UIColor redColor].CGColor), (id)(

Animate a layer property which simply changes other properties?

心已入冬 提交于 2019-12-01 04:58:46
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 like .. class CustomGradientLayer: CAGradientLayer { @objc var spinLike: CGFloat = 0 { didSet { startPoint = CGPoint( ... ) endPoint = CGPoint( ... ) setNeedsDisplay() } } } To animate spinLike ... class Test: UIView { ... g = CustomGradientLayer() a = CABasicAnimation(keyPath: "spinLike") ... g.add(a, forKey: nil) ... But. It doesn't work,

How to resize a CAGradientLayer after rotation?

这一生的挚爱 提交于 2019-11-30 17:49:31
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 view. Here's what I'm doing: CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.frame = CGRectMake(0.0, 0.0, frame.size.width, frame.size.height); gradientLayer.colors = [NSArray arrayWithObjects: (id)[[UIColor colorWithRed:255.0/255.0f green:255.0/255.0f blue:255.0/255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:233.0

Draw CAGradient within MKPolyLineView

老子叫甜甜 提交于 2019-11-30 07:37:28
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 zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context UIColor *darker = [UIColor blackColor]; CGFloat baseWidth = self.lineWidth / zoomScale; // draw the dark colour thicker CGContextAddPath(context, self.path); CGContextSetStrokeColorWithColor(context, darker.CGColor); CGContextSetLineWidth(context, baseWidth * 1.5); CGContextSetLineCap(context, self.lineCap);

How to resize a CAGradientLayer after rotation?

荒凉一梦 提交于 2019-11-30 01:22:12
问题 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 view. Here's what I'm doing: CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.frame = CGRectMake(0.0, 0.0, frame.size.width, frame.size.height); gradientLayer.colors = [NSArray arrayWithObjects: (id)[[UIColor colorWithRed

UIView transparent gradient

冷暖自知 提交于 2019-11-29 19:52:21
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 also can't overlay a PNG because the background will change as my subview is scrolled along its parent vertical scrollview (see image). I have a non-elegant fallback: have my uiview clip its subviews and move a pre-rendered gradient png of the background as the parent scrollview is scrolled. jpsim This was an embarrassingly easy fix: apply a

How to have a Gradient Layer's size placed behind a UITextField, match the UITextField size, after re-sizing the layout?

末鹿安然 提交于 2019-11-29 08:49:08
What you will see in the first image, if you scroll down a little bit, is the initial screen of a fin app. Basically, every section you see on the screen is placed within a vertical Stack View. Then every Label and Cell Is placed in a horizontal Stack View and so on, so the app auto-resizes for any screen size. I was using Story Board to create the elements. The last section has two blue UITextFields that have a gradient layer behind it. I created an extension UITextField Class in a separate file that has the gradient function constructor in it and then another Class that placed the gradient

How to apply CAGradientLayer as mask of another CALayer?

…衆ロ難τιáo~ 提交于 2019-11-29 01:13:22
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 = self.bounds; gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil]; //[self.layer insertSublayer:gradient atIndex:0]; self.layer.mask = gradient; If I replace self.layer.mask = gradient; with [self.layer insertSublayer:gradient atIndex:0]; then I see the gradient. It's from black

How to change CAGradientLayer color points?

≡放荡痞女 提交于 2019-11-28 19:11:18
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 is the code that I've got so far...I included core animation because I'm animation between colors. - (id)init { self = [super init]; UIView *gradientView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.w, self.h)]; [self addSubview:gradientView]; [self sendSubviewToBack:gradientView]; topColor = [UIColor colorWithRed:0.012 green:0.012 blue:0

CAGradientLayer diagonal gradient

↘锁芯ラ 提交于 2019-11-28 17:05:28
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 = CGPointMake(1, 0) layer.locations = [0.0, 0.6, 1.0] But when I set bounds property for the layer, it just stretches a square gradient. I need a result like in Sketch 3 app image (see above). How can I achieve this? Senseful Update: Use context.drawLinearGradient() instead of CAGradientLayer in a manner similar to the following . It will draw gradients that are consistent