今回はディゼーブル状態の描画を行う。
ディゼーブル状態の描画
Bezelボタンは UIControl のサブクラスなので有効/無効状態を表すプロパティ enabled を持っている。この値を見てディゼーブル状態の描画を行う。今回は画像の色を薄くしてみよう。具体的には alpha値を下げて半透明化する。
こんなかんじ。
- (void)drawImageOnContext:(CGContextRef)context offset:(CGPoint)offset
{
if (self.image) {
CGRect buttonFrame = [self bounds];
CGRect imageFrame = CGRectInset(buttonFrame, IMAGE_PADDING, IMAGE_PADDING);
imageFrame.origin.x += offset.x;
imageFrame.origin.y += offset.y;
if (self.enabled) {
[self.image drawInRect:imageFrame];
} else {
[self.image drawInRect:imageFrame blendMode:kCGBlendModeNormal alpha:0.5];
}
}
}半透明に画像を描くには -[UIImage drawInrect:blendMode:alpha:]を使う。実行結果:
enabled == YES
enabled == NO





Responses
Leave a Response