ios - 如何增加颜色空间CAGradientLayer

标签 ios cagradientlayer

我有一个具有三种颜色的渐变,黑色、透明和黑色。你会如何增加中间部分?

我想要的效果是顶部有阴影/渐变,清晰的中间显示内容可以清晰显示,底部有阴影/渐变。这是我目前所拥有的。

enter image description here

如何增加渐变的中间部分?我希望它清楚。这也是我的代码;

CAGradientLayer *gradient = [CAGradientLayer layer];

gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor],(id)[[UIColor clearColor]CGColor],(id)[[UIColor blackColor] CGColor],nil];
[self.view.layer addSublayer:gradient];

最佳答案

尝试使用 gradient.locations

gradient.locations = @[@(0.2), @(0.8), @(1.0)];

关于ios - 如何增加颜色空间CAGradientLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26176847/

相关文章:

ios - Itunes系列连接设备,仅适用于iPhone

ios - 如何在 iOS 中绘制带弧形边缘的圆弧?

swift - 渐变层未显示在 UIButton 上

ios - 渐变不填满所有的UIView

ios - 在 MKPolyLine View 中绘制渐变

ios - 在 UITableViewCell 中使用时,CAGradientLayer 在 UIView 上溢出

ios - 如何在 swift 中从 childViewContoller 刷新 parentViewContoller?

iphone - 预期标识符?什么?

ios - SpriteKit 中的场景

ios - 从数组索引 obj c 加载某些信息