From: http://www.xue5.com/Mobile/iOS/681739.html
Most of the time, when you need to design a more advanced ui or reduce the workload of the designer, we need to use the code to draw the UI, you need to use the CoreGraphics framework to draw the UI by yourself (OpenGL is of higher order and has not yet reached this level ).
Cgcontext class, equivalent to the canvas in Android, uses uigraphicsgetcurrentcontext () to obtain the reference cgcontextref of the current cgcontext. WeThe original state should be saved before each painting. After the painting is completed, the original state will be restored.. So cgcontextsavegstate (CTX );... Cgcontextrestoregstate (CTX); All should appear in pairs, and the Code for drawing the UI between them should be used.
The cgpath class is used to describe the drawn area or route. In cgcontext, addline and addrect are actually adding the path. After adding the path, we can choose whether to fill the path or stroke the path. Set the corresponding color and line width. If we only need to draw in a certain area, we can use cgcontextclip (CTX) to crop the current canvas after the path is described.
Cgaffinetransform is a structure of an affine transformation. It is equivalent to a matrix used for geometric Transformation (translation, rotation, scaling) of two-dimensional planes. These geometric transformations have been encapsulated for function callability,The order of transformation is the order of matrix concatenation. Do not reverse the order of matrix concatenation. Otherwise, the result may be different..
Cgcolorspace class is used for interface color display. Generally, the color is composed of four types: rgba (red, green, blue, and transparency). cgcolorspacecreatedevicergb is used to obtain reference cgcolorspace cgcolorspaceref,Note that in CoreGraphics, you must call the release method to release the reference generated by using the create method.For example, cgcolorspacecreatedevicergb () corresponds to cgcolorspacerelease (RGB ).
Expand code
# Define uicolorfromhex (hexvalue) [uicolor \
Colorwithred :( (float) (hexvalue & 0xff0000)> 16)/255.0 \
Green :( (float) (hexvalue & 0xff00)> 8)/255.0 \
Blue :( (float) (hexvalue & 0xff)/255.0 ALPHA: 1.0]
Expand code