Search code examples
iosobjective-ciphoneios7

Custom circle progress view


I search a lot, but cant find control like this in internet. Can you help me to do this my own?

https://i.sstatic.net/KO9ec.png


Solution

  • Take white circle image like you displayed in above image and try following code.

    - (void)startSpin
    {
        if (!animating)
        {
            animating = YES;
            [self spinWithOptions: UIViewAnimationOptionCurveEaseIn];
        }
    }
    
    - (void)spinWithOptions:(UIViewAnimationOptions) options
    {
        [UIView animateWithDuration: 1.0f
                          delay: 0.0f
                        options: options
                     animations: ^{
                         imgViewCircle.transform = CGAffineTransformRotate(imgViewCircle.transform, M_PI / 2);
                     }
                     completion: ^(BOOL finished) {
                         if (finished) {
                             if (animating) {
                                 // if flag still set, keep spinning with constant speed
                                 [self spinWithOptions: UIViewAnimationOptionCurveLinear];
                             } else if (options != UIViewAnimationOptionCurveEaseOut) {
                                 // one last spin, with deceleration
                                 [self spinWithOptions: UIViewAnimationOptionCurveEaseOut];
                             }
                         }
                     }];
    }