Core graphics framework

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.