Ahufford
Ahufford

Reputation: 488

UIProgressView Subclassing for custom Colors

I'm trying to subclass ProgressView to use as a health bar for a game and when I try to override the setProgress, it isn't called.

I want the color to change based on the progress float value.

Here is the code I tried to use:

@interface AHHealthbar : UIProgressView
...
- (void)setProgress:(float)progress animated:(BOOL)animated
{

if (progress > .5)
{
    self.progressTintColor = [UIColor greenColor];
}

if (progress <= .5 && self.progress >= .2)
{
    self.progressTintColor = [UIColor yellowColor];
}

if (progress < .2) {
    self.progressTintColor = [UIColor redColor];

}

[super setProgress:progress animated:animated];
}

Does any one have an idea of how to override this? Or any better ideas?

Upvotes: 1

Views: 919

Answers (1)

StilesCrisis
StilesCrisis

Reputation: 16290

You might need to also override -setProgress:.

Upvotes: 1

Related Questions