我有一个CAGradientLayer插入到应用程序底部弹出的这个小细节视图的底部.正如你所看到的,我将颜色从白色设置为清晰,但是出现了这种奇怪的灰色色调.有任何想法吗?
// Set up detail view frame and gradient
[self.detailView setFrame:CGRectMake(0, 568, 320, 55)];
CAGradientLayer *layer = [CAGradientLayer layer];
layer.frame = self.detailView.bounds;
layer.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
layer.startPoint = CGPointMake(1.0f, 0.7f);
layer.endPoint = CGPointMake(1.0f, 0.0f);
[self.detailView.layer insertSublayer:layer atIndex:0];
Run Code Online (Sandbox Code Playgroud)
这是有问题的观点:
我一直试图产生一个基本的径向渐变背景,但没有成功.我设法得到一个线性渐变工作,如下面的代码所示,但我不知道如何使其不同的颜色径向 - 如下图所示.任何帮助将不胜感激.:)
override func viewDidLoad() {
super.viewDidLoad()
//A linear Gradient Consists of two colours: top colour and bottom colour
let topColor = UIColor(red: 15.0/255.0, green: 118.0/255.0, blue: 128.0/255.0, alpha: 1.0)
let bottomColor = UIColor(red: 84.0/255.0, green: 187.0/255.0, blue: 187.0/255.0, alpha: 1.0)
//Add the top and bottom colours to an array and setup the location of those two.
let gradientColors: [CGColor] = [topColor.CGColor, bottomColor.CGColor]
let gradientLocations: [CGFloat] = [0.0, 1.0]
//Create a Gradient CA layer
let gradientLayer: CAGradientLayer = CAGradientLayer() …Run Code Online (Sandbox Code Playgroud) 我有一个UIScrollView,我需要将底部淡入淡出,以便它不会突然切断内容.UIScrollView的背景是自定义颜色.这是我到目前为止,但图层显示为白色,而不是自定义颜色.这就是我想要的,但仅限于底层.
:
这是我到目前为止:
maskLayer = [CAGradientLayer layer];
CGColorRef firstColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:1.0].CGColor;
CGColorRef secondColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.8].CGColor;
CGColorRef thirdColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.2].CGColor;
CGColorRef fourthColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.0].CGColor;
maskLayer.colors = [NSArray arrayWithObjects:(__bridge id)firstColor, (__bridge id)secondColor, (__bridge id)thirdColor, (__bridge id)fourthColor, nil];
maskLayer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.2],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0], nil];
maskLayer.frame = CGRectMake(0, 285, self.loginScrollView.frame.size.width, 40);
maskLayer.anchorPoint = CGPointZero;
[self.loginScrollView.layer addSublayer:maskLayer];
Run Code Online (Sandbox Code Playgroud)
由于某种原因,图层显示为白色,只有scrollView的一半宽度.