今回は Quartz 2D を使い影を描く。
影を描く
CGContextSetShadow()を使う。CGContext Reference
こんな感じ。
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect frame = CGRectInset([self bounds], 4.0f, 4.0f);
CGContextSetShadow(context, CGSizeMake(3.0f, -3.0f), 2.0f);
[[UIColor whiteColor] set];
[self addRoundRectPath:context rect:frame];
CGContextFillPath(context);
}最初に呼び出しておけば、それ以降の描画に影がつく。
[実行例]
影付けをoffにする関数は無いので、on/offを制御したい場合は CGContextSaveGState() と CGContextStoreGState() を組みで使う。
(例) : CGContextSaveGState(context); CGContextSetShadow(context, CGSizeMake(3.0f, -3.0f), 2.0f); : 影付き描画 : CGContextRestoreGState(context) : 影なし描画 :




Responses
Leave a Response