cagradientlayer

Add a gradient on UIImageView

徘徊边缘 提交于 2020-07-28 13:04:26
问题 I am trying to add a sublayer on my UIImageView but it doesn't work. I have a set of 10 images named from photo0 to photo9 and I display it with a timer of 5s. The outlet shanghaiImage is my background I would like to add a gradient on top of this marty like: transparent (top) to black (bottom). Thanks for the help :) Here is my code in Swift 3. This part is fine : import UIKit class ViewController: UIViewController { @IBOutlet weak var shanghaiImage: UIImageView! // beginning index var

Add a gradient on UIImageView

落爺英雄遲暮 提交于 2020-07-28 13:04:22
问题 I am trying to add a sublayer on my UIImageView but it doesn't work. I have a set of 10 images named from photo0 to photo9 and I display it with a timer of 5s. The outlet shanghaiImage is my background I would like to add a gradient on top of this marty like: transparent (top) to black (bottom). Thanks for the help :) Here is my code in Swift 3. This part is fine : import UIKit class ViewController: UIViewController { @IBOutlet weak var shanghaiImage: UIImageView! // beginning index var

Apply gradient on a UIView not working

五迷三道 提交于 2020-05-26 05:04:34
问题 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 someone help me figure out what I'm doing wrong here? let sundayView = UIView() override func viewDidLoad() { super.viewDidLoad() setupViews() setupSundayView() } func setupViews() { sundayView.translatesAutoresizingMaskIntoConstraints = false view

Gradient Layer over ImageView reuse

こ雲淡風輕ζ 提交于 2020-01-17 05:37:31
问题 Within my 'cellForRowAtIndexPath' I have the following code to populate the image (async) and apply a custom gradient This worked fine, until I added a custom colour per cell. What it's currently doing is recycling the previous colour rather than applying a new one - this is presumably due to the following line which will skip the gradient code once applied to each cell: if(!cell.gradientMask){ However, if I comment this out, the colours work but the gradient on each cell will stack up as a

UIView layer's sublayers display differently/randomly each time view appears

限于喜欢 提交于 2020-01-14 03:43:09
问题 I have a simple custom CALayer to create an overlaying gradient effect on my UIView. Here is the code: class GradientLayer: CALayer { var locations: [CGFloat]? var origin: CGPoint? var radius: CGFloat? var color: CGColor? convenience init(view: UIView, locations: [CGFloat]?, origin: CGPoint?, radius: CGFloat?, color: UIColor?) { self.init() self.locations = locations self.origin = origin self.radius = radius self.color = color?.CGColor self.frame = view.bounds } override func drawInContext

ios - Transparent radial Gradient Layer Mask

不羁的心 提交于 2020-01-03 06:05:10
问题 I'm using a CAGradientLayer to as a layer to my image. Im using this code: UIImage *image = [UIImage imageNamed:@"perfect.jpg"]; [testImage setImage:image]; CAGradientLayer *myLayer = [CAGradientLayer layer]; myLayer.anchorPoint = CGPointZero; //starts in bottom left myLayer.startPoint = CGPointMake(0.0f,0.5f); //ends in top right myLayer.endPoint = CGPointMake(0.5f, 0.0f); UIColor *outerColor = [UIColor colorWithWhite:1.0 alpha:0.0]; UIColor *innerColor = [UIColor colorWithWhite:1.0 alpha:1

Misplaced CAGradientLayer on iPhone 6s

怎甘沉沦 提交于 2020-01-03 02:32:05
问题 I have a few UILabels with colored background and I added CAGradientLayers to them like below. CAGradientLayer * gradientLayer = [CAGradientLayer layer]; gradientLayer.colors = [NSArray arrayWithObjects: (id) [UIColor colorWithWhite:1 alpha:0.3].CGColor, (id) [UIColor colorWithWhite:0.5 alpha:0.3].CGColor, nil]; gradientLayer.frame = label.bounds; gradientLayer.cornerRadius = label.layer.cornerRadius; [label.layer insertSublayer:gradientLayer atIndex:0]; On iPhone 4 and iPhone 5s it looks

How to give “locations” to CAGradientLayer

允我心安 提交于 2019-12-31 12:53:33
问题 I have created CAGradientLayer having three colors, i need to give each color different locations. Example: Red = 0 to 50 % Yellow = 51 to 80 % Green = 81 to 100 % I have tried with giving startPoint and endPoint but it did not work. 回答1: If you put the following code into a Playground you will get the exact desired output: let view = UIView(frame: CGRectMake(0,0,200,100)) let layer = CAGradientLayer() layer.frame = view.frame layer.colors = [UIColor.greenColor().CGColor, UIColor.yellowColor(

How to give “locations” to CAGradientLayer

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 12:52:15
问题 I have created CAGradientLayer having three colors, i need to give each color different locations. Example: Red = 0 to 50 % Yellow = 51 to 80 % Green = 81 to 100 % I have tried with giving startPoint and endPoint but it did not work. 回答1: If you put the following code into a Playground you will get the exact desired output: let view = UIView(frame: CGRectMake(0,0,200,100)) let layer = CAGradientLayer() layer.frame = view.frame layer.colors = [UIColor.greenColor().CGColor, UIColor.yellowColor(