私はカスタムUITableViewCell
クラスを持っています。その中でdrawRect
メソッドをオーバーライドして、素晴らしいグラデーションの背景を作成しました。しかし、私は1つのケースのグラデーションのみを必要とし、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);
}
それは私が固体をしたいときのグラデーションを描画する愚かなようです。助言がありますか?
あなたが代替を見つけるために、AppleのQuartz2Dの参考資料を見ていたことがありますか? –
ありがとうございます - 私が行った最初のQuartzコードは、参考資料のどこに見えるかわかりませんでした。 – squarefrog