Calayer Use note

Source: Internet
Author: User

Set up a picture to display
mylayer.contents=(ID)[UIImage imagenamed:@ "Me"]. Cgimage;

Here is the Cgimage property of UIImage, which is a cgimageref type of data.

1.CGColorRef and CGIMAGEREF data types

1. Brief description

Calayer is defined in the Quartzcore framework; cgimageref, cgcolorref two data types are defined in the Coregraphics framework; Uicolor, uiimage are defined in the Uikit framework.

Second, the Quartzcore framework and the Coregraphics framework are available across platforms and can be used on both iOS and Mac OS x, but Uikit can only be used in iOS

Therefore, in order to ensure portability, quartzcore can not use UIImage, Uicolor, can only use Cgimageref, Cgcolorref

However, in many cases, the Coregraphics object can be obtained by Uikit the specific method of the object, such as UIImage Cgimage method can return a cgimageref.

Selection of 2.UIView and Calayer

You can see that the previous 2 effects can be implemented not only by adding layers, but also by adding uiview. The layer that displays the picture can be implemented with a uiimageview. Since Calayer and UIView all can achieve the same display effect, then who should choose who is good?

In fact, compared with the Calayer,uiview more than one event processing function. In other words, Calayer cannot handle user touch events, while UIView can.

Therefore, in the process of selection, you need to take into account the actual situation, if the displayed things need to interact with the user, with UIView, if you do not need to interact with the user, with UIView or Calayer can

Of course, the performance of Calayer is higher because it is less capable of event handling and more lightweight

Calayer Use note

Related Article

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.