相关疑难解决方法(0)

将渐变颜色应用于使用UIBezierPath创建的弧

我想创建一个具有弧形的进度条.进度条的颜色必须根据值进行更改.

我使用创建了一个弧UIBezierPath bezierPathWithArcCenter.我使用了以下代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    int radius = 100;

    CAShapeLayer *arc = [CAShapeLayer layer];

    arc.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 50) radius:radius startAngle:60.0 endAngle:0.0 clockwise:YES].CGPath;

    arc.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius,
                                  CGRectGetMidY(self.view.frame)-radius);

    arc.fillColor = [UIColor clearColor].CGColor;
    arc.strokeColor = [UIColor purpleColor].CGColor;
    arc.lineWidth = 15;

    [self.view.layer addSublayer:arc];

    CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    drawAnimation.duration            = 5.0; // "animate over 10 seconds or so.."
    drawAnimation.repeatCount         = 1.0;  // Animate only once..
    drawAnimation.removedOnCompletion = NO;   // Remain stroked after the animation..
    drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; …
Run Code Online (Sandbox Code Playgroud)

xcode uicolor ios uibezierpath

25
推荐指数
2
解决办法
1万
查看次数

绘图环的渐变类似于Apple Watch健身应用程序

我是Core Graphics的新手,我想知道如何使用类似于Apple Watch健身应用程序的渐变绘制环.我试图在iOS应用程序上执行此操作,因为我认为目前尚未在WatchKit上支持Core Graphics.

我在以下网站上找到了一个非常好的教程来绘制戒指.

http://makeapppie.com/2015/03/10/swift-swift-basic-core-graphics-for-the-ring-graph/

但是我想弄清楚如何为笔触颜色添加渐变.到目前为止,基于我发现的,没有直接的方法来做到这一点.为了达到这个目的,我想我需要找到以下答案:

  • 是否有API在Core Graphics中创建圆形渐变?
  • 是否可以在Core Graphics中将渐变应用为笔触颜色?

谢谢

core-graphics ios swift

5
推荐指数
1
解决办法
1590
查看次数

标签 统计

ios ×2

core-graphics ×1

swift ×1

uibezierpath ×1

uicolor ×1

xcode ×1