我創建了一個自定義的進度條,它的子類UIView並實現了drawRect。我設法在整個視圖上繪製一個漸變。然而,我想繪製幾個不同的漸變,每個漸變都處於不同的位置。如何將CGContextDrawLinearGradient
限制在我的視圖內的較小矩形?iOS在視圖的一部分繪製漸變
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGPoint topCenter = CGPointMake(start + (CGRectGetMidX(currentBounds)/currentBounds.size.width), 0.0f);`
CGPoint midCenter = CGPointMake(start + (CGRectGetMidX(currentBounds)/currentBounds.size.width), currentBounds.size.height);
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0);
start = start + (values[i]/currentBounds.size.width);
CGGradientRelease(glossGradient);
}
這正是我所缺少的 - 謝謝! – nambar 2011-12-30 06:46:34