0

Progress Bar

I'm trying to setup a view that will display progress with these dots instead of a solid bar. Ideally, I'd like to have the dots fill vertically (Bottom to top).

I have two UIImageViews inside of a UIView, one for the grey background and one with the foreground masked.

 UIImage * bgImg = [UIImage imageNamed:@"prog_bg.png"];
    UIImageView * bgView = [[UIImageView alloc] initWithImage:bgImg];
    progImage = [UIImage imageNamed:@"prog.png"];
    maskRef = [UIImage imageNamed:@"prog_mask.png"].CGImage;
    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                        CGImageGetHeight(maskRef),
                                        CGImageGetBitsPerComponent(maskRef),
                                        CGImageGetBitsPerPixel(maskRef),
                                        CGImageGetBytesPerRow(maskRef),
                                        CGImageGetDataProvider(maskRef), NULL, false);

    CGImageRef maskedImage = CGImageCreateWithMask([progImage CGImage], mask);
    UIImage * img = [UIImage imageWithCGImage:maskedImage];
    imageView = [[UIImageView alloc] initWithImage:img];
    [progView addSubview:bgView];
    [progView addSubview:imageView];

I found the code in this SO question. I can't seem to define the width of the mask from my delegate that updates the progress.

Community
  • 1
  • 1
ChickensDontClap
  • 1,871
  • 4
  • 22
  • 39

1 Answers1

1

Can you try CGImageGetWidth(maskRef) * percentage in CGImageMaskCreate

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
  • I'm sorry I don't understand. Would I need to also recreate the mask each time an update to the progress occurs? Just putting that code in had no effect. – ChickensDontClap May 23 '12 at 14:23