1

I want to use progress view using custom images for that i wrote following code in viewDidLoad,

UIView *v = [[UIView alloc] initWithFrame:CGRectMake(20, 281, 260, 33)];
v.backgroundColor = [UIColor darkGrayColor];
progressTest = [[customprogress alloc] initWithFrame:CGRectMake(5, 9, 250, 15)];
progressTest.progress = 0.0;
[v addSubview:progressTest];
[self.view addSubview:v];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startProgressing) userInfo:nil repeats:YES];

and this is my customprogress.m file,

- (void)drawRect:(CGRect)rect {
UIImage *background = [[UIImage imageNamed:@"progressbarbg.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 4)];
UIImage *fill = [[UIImage imageNamed:@"progressbarfill.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 4)];
[background drawInRect:rect];
NSInteger maxWidth = rect.size.width;
NSInteger curWidth = floor([self progress] * maxWidth);
CGRect fillRect = CGRectMake(rect.origin.x,rect.origin.y+1,curWidth,rect.size.height-2);
[fill drawInRect:fillRect];
}

This is my startProgressing method

-(void) startProgressing {
float t = progressTest.progress;
seconds = (secondsLeft %3600) % 60;

progressTest.progress = t + seconds;

}

I am getting weird progress view which does not progress at all.I want to show progress view for 60 sec.How can i do that?

I am seeing just a rectangle with dark gray bgcolor.

Ankit Gohel
  • 77
  • 11

1 Answers1

0

It's hard to say why exactly the code you provided isn't working.

Are you sure you want to create a custom progress view? There's a brilliant third-party library called MBProgressHUD that is easy to use and customise.

MBProgressHUD is an iOS drop-in class that displays a translucent HUD with an indicator and/or labels while work is being done in a background thread. The HUD is meant as a replacement for the undocumented, private UIKit UIProgressHUD with some additional features.

Rinat Khanov
  • 1,566
  • 10
  • 32
  • I dont want to use third-party library.Please help me with the problem. – Ankit Gohel Aug 05 '14 at 05:59
  • @AnkitGohel Can you update your question with the contents of `startProgressing` method and describe what behaviour you're seeing with your current implementation? – Rinat Khanov Aug 05 '14 at 06:01