IOS4 note 16 (6) Graphics Context State

Graphics Context State

When you draw in a graphics context, the drawing obeys the context’s current settings. Thus, the way you draw using Core Graphics functions is to configure the context’s settings first, and then draw. For example, to draw a red line followed by a blue line, you would first set the context’s  line color to red, and then draw the first  line; then you’d set the context’s line color to blue, and then draw the second line. To the eye, it appears that the redness and blueness are properties of the individual lines, but in fact, at the time you draw each of them, they are properties of the entire graphics context. 

A graphics context thus has, at every moment, a state, which is the sum total of all its settings; the way a piece of drawing looks is the result of what the graphics context’s state was at the moment that piece of drawing was performed. To help you manipulate entire states, the graphics context provides a stack for holding states. Every time you call CGContextSaveGState, the context pushes the entire current state onto the stack; every time you call CGContextRestoreGState, the context retrieves the state from the top of the stack (the state that was most recently pushed) and sets itself to that state. Many of the settings that constitute a graphics context’s state, and that determine the behavior and appearance of drawing performed at that moment, are similar to those of any drawing application. They include (along with some of the commands that determine them):

Line thickness and dash style

CGContextSetLineWidth, CGContextSetLineDash

Line end-cap style and join style

CGContextSetLineCap, CGContextSetLineJoin, CGContextSetMiterLimit

Line color or pattern

CGContextSetRGBStrokeColor, CGContextSetGrayStrokeColor, CGContextSetStrokeColorWithColor, CGContextSetStrokePattern

Fill color or pattern

CGContextSetRGBFillColor,  CGContextSetGrayFillColor,  

CGContextSetFillColorWithColor, CGContextSetFillPattern

Shadow

CGContextSetShadow, CGContextSetShadowWithColor

Blend mode

CGContextSetBlendMode (this determines how drawing that you do now will be composited with drawing already present)

Overall transparency

CGContextSetAlpha (individual colors also have an alpha component)

Text features

CGContextSelectFont, CGContextSetFont, CGContextSetFontSize, CGContextSetTextDrawingMode, CGContextSetCharacterSpacing

Whether anti-aliasing and font smoothing are in effect

CGContextSetShouldAntialias, CGContextSetShouldSmoothFonts

 

Additional settings include:

Clipping area

Drawing outside the clipping area is not physically drawn.

Transform (or “CTM,” for “current transform matrix”)

Changes how points that you specify in subsequent drawing commands are mapped onto

the physical space of the canvas.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值