NSProgress进度条只有两种风格: UIProgressViewStyleDefault, // normal progress bar
UIProgressViewStyleBar, // for use in a toolbar
我现在想使用UIProgressViewStyleDefault风格,但是它的进度条的颜色是蓝色的,我想把它改成绿色的!因为progress没有color的属性,我就想到重写- (void)drawRect:(CGRect)rect;函数。但是不知道怎么将进度条颜色更改。
各位大虾给点主意吧!
UIProgressViewStyleBar, // for use in a toolbar
我现在想使用UIProgressViewStyleDefault风格,但是它的进度条的颜色是蓝色的,我想把它改成绿色的!因为progress没有color的属性,我就想到重写- (void)drawRect:(CGRect)rect;函数。但是不知道怎么将进度条颜色更改。
各位大虾给点主意吧!
{
[self setBackgroundColor:[UIColor clearColor]];
}
// allow non-clear background color in Interface Builder, but do not draw it
- (BOOL)getClearsContextBeforeDrawing
{
return NO;
};
// draw left and right edge of progress bar with filled sections between
- (void)drawRect:(CGRect)rect{
const int numParts = 10;
UIImage *pb_left = [UIImage imageNamed:@"pb_left.png"];
// "[" UIImage *pb_right = [UIImage imageNamed:@"pb_right.png"];
// "]" UIImage *pb_on = [UIImage imageNamed:@"pb_on.png"];
// "X" UIImage *pb_off = [UIImage imageNamed:@"pb_off.png"];
// " " CGPoint p = {0,0};
[pb_left drawAtPoint:p];
p.x = pb_left.size.width;
int q = (int)(self.progress * numParts);
for (int i=0; i<numParts; i++)
{
if (i == q) // partial on/off section. works with semi-transparent images too
{
float w = truncf(pb_on.size.width * fmodf(self.progress * numParts, 1.0f));
[pb_on drawInRect:CGRectMake(p.x, p.y, w, pb_on.size.height)];
[pb_off drawInRect:CGRectMake(p.x + w, p.y, pb_on.size.width - w, pb_on.size.height)];
}
else if (i < q)
{
[pb_on drawAtPoint:p];
}
else // (i > q)
{
[pb_off drawAtPoint:p];
}
p.x += pb_on.size.width;
}
[pb_right drawAtPoint:p];
}
http://darkfader.blogspot.com/2009/06/uiprogressview-custom-draw-method.html