我有一個自定義的UITableViewCell
類,並在其中我重寫了drawRect
方法產生一個不錯的漸變背景。但是,我只想要一個案例的漸變,並使用if
語句進行切換。drawLinearGradient(),但爲純色
有沒有更好的方法來寫這個?
- (void) drawRect:(CGRect)rect {
// Setup gradient
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef topColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0].CGColor;
CGColorRef bottomColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0].CGColor;
CGRect cellRect = self.bounds;
if (!isDescription)
drawLinearGradient(context, cellRect, topColor, bottomColor);
else
drawLinearGradient(context, cellRect, bottomColor, bottomColor);
}
當我想要一個堅實的東西時,它似乎很愚蠢的畫一個漸變。有什麼建議麼?
你有沒有看看蘋果的Quartz2D參考材料找到替代? – 2012-01-27 11:46:30
謝謝 - 我真的不知道在參考資料中的位置,因爲這是我所做的第一個Quartz代碼。 – squarefrog 2012-01-27 12:06:55