3 回答

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
在當(dāng)前代碼中,保存GState當(dāng)前上下文的,將其配置為繪制陰影..并將其還原到配置為繪制陰影之前的狀態(tài)。然后,最后,您調(diào)用超類的實(shí)現(xiàn)drawRect:。
任何應(yīng)受陰影設(shè)置影響的繪圖都需要在之后進(jìn)行
CGContextSetShadow(currentContext, CGSizeMake(-15, 20), 5);
但是之前
CGContextRestoreGState(currentContext);
因此,如果您希望將超類drawRect:包裹在一個(gè)陰影中,那么如果您這樣重新排列代碼又如何呢?
- (void)drawRect:(CGRect)rect {
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(currentContext);
CGContextSetShadow(currentContext, CGSizeMake(-15, 20), 5);
[super drawRect: rect];
CGContextRestoreGState(currentContext);
}
- 3 回答
- 0 關(guān)注
- 749 瀏覽
添加回答
舉報(bào)