cagradientlayer

Swift: gradient on a cell of a tableview

本秂侑毒 提交于 2019-12-31 05:23:04
问题 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 = self.tableView?.dequeueReusableCellWithIdentifier("cell") as UITableViewCell cell.backgroundColor=UIColor.clearColor() let gradient : CAGradientLayer = CAGradientLayer() var arrayColors:Array<AnyObject> = [UIColor.blackColor().CGColor, UIColor.whiteColor().CGColor] gradient

Swift -Animation in GradientLayer not appearing in cell

こ雲淡風輕ζ 提交于 2019-12-25 01:16:00
问题 I have different images of different foods that I add to a UIView (I choose to use an UIView instead of an UIImageView ). The original color of the images are black and I change them to .lightGray using .alwaysTemplate . // the imageWithColor function on the end turns it .lightGray: [https://stackoverflow.com/a/24545102/4833705][1] let pizzaImage = UIImage(named: "pizzaImage")?.withRenderingMode(.alwaysTemplate).imageWithColor(color1: UIColor.lightGray) foodImages.append(pizzaImage) I add the

Radial CAGradientLayer not rendering properly at runtime

老子叫甜甜 提交于 2019-12-24 19:42:54
问题 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 (solely for the CAGradientLayer), it shows a beautiful radial CAGradientLayer. However, when I use this view and look at it at runtime in the simulator, it looks awful. I don't know what I'm doing wrong. This is the code for the CAGradientLayer:

How to draw Arc with curved edge in iOS?

冷暖自知 提交于 2019-12-21 19:57:29
问题 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 arcWithRoundedCornerAt:centerPoint startAngle:DEGREES_TO_RADIANS(-90) endAngle:DEGREES_TO_RADIANS(90) innerRadius:width-20 outerRadius:width cornerRadius:0]; CAShapeLayer *mask = [CAShapeLayer new]; [mask setPath:roundedArc.CGPath]; [mask setFrame:_outerView.bounds]; [mask

Subviews are not displaying for CAGradientLayer added view [duplicate]

↘锁芯ラ 提交于 2019-12-20 07:48:39
问题 This question already has answers here : How to Apply Gradient to background view of iOS Swift App (25 answers) Closed last year . used below code for adding gradient layer for a view. After adding gradient layer to a view if i tried to add new subviews inside my gradient view the new view are not getting displayed func setGradientBackground(_ view: UIView ,colorStart:CGColor ,colorEnd:CGColor,cornerRadius:CGFloat) { let gradientLayer = CAGradientLayer() gradientLayer.colors = [colorStart,

Making Gradient Background in Swift - The Right Way

大憨熊 提交于 2019-12-20 07:45:09
问题 This is my code for a gradient background. When I apply it on my view, it hides all my stuff on that VC, like it's on the front and everything else is pushed back. How can I make a gradient view that is not interfering with my elements? I'm using @IBDesignable just to see how is it looking in Storyboard. import UIKit @IBDesignable class GradientView: UIView { private let gradientLayer = CAGradientLayer() var color1 = ColorPalette.GrdTop var color2 = ColorPalette.GrdBottom override init(frame:

How can I add a gradient that spans two views?

孤人 提交于 2019-12-20 03:11:36
问题 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 blueColor].CGColor, (id)[UIColor redColor].CGColor]; [view.layer insertSublayer:gradient atIndex:0]; 回答1: There are several ways you could do this. Here's one way: Create a UIView subclass named GradientView to manage the gradient layer. This is helpful because it

Animate a layer property which simply changes other properties?

半城伤御伤魂 提交于 2019-12-19 07:07:13
问题 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

Swift: rainbow colour circle

本秂侑毒 提交于 2019-12-18 13:37:57
问题 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: self.wheelView.frame.width/2, y: self.wheelView.frame.height/2), radius: CGFloat(self.wheelView.frame.height/2), startAngle: CGFloat(0), endAngle:CGFloat(Double.pi * 2), clockwise: true) let shapeLayer = CAShapeLayer() shapeLayer.path = circlePath.cgPath //color

Swift: rainbow colour circle

别来无恙 提交于 2019-12-18 13:37:04
问题 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: self.wheelView.frame.width/2, y: self.wheelView.frame.height/2), radius: CGFloat(self.wheelView.frame.height/2), startAngle: CGFloat(0), endAngle:CGFloat(Double.pi * 2), clockwise: true) let shapeLayer = CAShapeLayer() shapeLayer.path = circlePath.cgPath //color