Making a visual bar timer for iPhone

Posted by Ohmnastrum on Stack Overflow See other posts from Stack Overflow or by Ohmnastrum
Published on 2010-05-27T19:10:13Z Indexed on 2010/05/27 19:11 UTC
Read the original article Hit count: 178

Filed under:

I've looked up all results for progress bars and changing the width of an image but it only refers to scaling, and the progress bars aren't customizable so that they fit other functions or design schemes... unless I missed that part. I'm trying to make a bar timer that crops off of the right over a period of time. I tried using an NStimer so that it would subtract from a value each time its function is called. the Timerbar function gets called as a result of another timer invalidating and it works. What doesn't work is that the width isn't changing just the position. further more I keep getting values like Inf and 0 for power and pwrBarWidth I was sure that the changes would occur when Mult was plugged into the equation. it seems like casting mult as an int is causing problems but i'm not sure exactly how.

int pwrBarMaxWidth = 137;
int pwrBarWidth 0;
int limit = 1;
float mult;
float power = 0;



-(void) Timerbar:(NSTimer *)barTimer {


 if(!waitForPlayer) {

  [barTimer invalidate];

 }
 if(mult > 0.0) {
  mult -= 0.001 * [colorChoices count];
  if(mult < 0.0) { 
   mult = 0.0;

  }

 } 
 power =  (mult * 10) / pwrBarMaxWidth; 
 pwrBarWidth = (int)power  % limit; // causes the bar to repeat after it reaches a certain point
 //At this point however the variable Power is always "inf" and PwrBarWidth is always 0.


 [powerBar setBounds:CGRectMake(powerBar.frame.origin.x, 
          powerBar.frame.origin.y,pwrBarWidth,20)]; //supposed to change the crop of the bar
}

Any reason why I'm getting inf as a value for power, 0 as a value for pwrBarWidth, and the bar itself isn't cropping? if this question is a bit vague i'll provide more information as needed.

© Stack Overflow or respective owner

Related posts about iphone