IOS calayer details

Source: Internet
Author: User

Calayer is a frequently used object. It is very common and important. It also has many attributes. Well, you must learn more.

The principle of calayer is hard to understand. Because I only focus on application at present, I will talk about some areas that can be used in actual development.

To change the calayer of the uiview, reference: # import <quartzcore/quartzcore. h>.

The following two articles are recommended:Article: Article 1: detailed introduction of principles; 2: Official article

Why is calayer important: 1. each uiview has a calayer, that is, uiview. at the same time, uiview is the basis of interface elements in IOS systems, and all interface elements are inherited from it. Therefore, calayer is widely used. calayer can make many settings for uiview, such as shadow, border, rounded corner, and transparent effect. These settings are useful. This article prohibits any website from reprinting and severely condemn the worms.
This article was first published in, blog garden. Please search: blog garden-Find yourself and view the original article
The first address of this article: IOS calayer The following describes some important calayer attributes one by one: 1. shadowpath: Set the location of the calayer background (shodow. shadowoffset: the direction of shadow extending on the X and Y axes, that is, the size of Shadow 3. shadowopacity: Shadow transparency 4. shadowradius: gradient distance of shadow. The shadowradius distance is 5 from the periphery to the center. maskstobounds: a very important attribute. This attribute can be used to prevent child element size overflow from parent element. If this attribute is used to prevent overflow, set it to true 6. borderwidth and boardercolor: border color and width, usually 7. bounds: an attribute that is difficult for me. I did not fully understand it after testing for half a day. I only knew that it can be used to control the size of the uiview, but cannot control the position 8. opacity: transparent effect of uiview 9. cornerradius : Uiview rounded corners this article prohibits reprinting on any website and severely condemn the worms.
This article was first published in, blog garden. Please search: blog garden-Find yourself and view the original article
The first address of this article: IOS calayer TestCode:
-( Void  ) Viewdidload {[Super viewdidload]; uiview * Viewsample =[[Uiview alloc] init]; [self. View addsubview: viewsample]; viewsample. backgroundcolor = [Uicolor greencolor]; viewsample. Frame = Cgrectmake ( 100 , 100 , 400 , 400  );  //  Test 1 shadow  //  Viewsample. layer. shadowpath = [uibezierpath bezierpathwithrect: viewsample. bounds]. cgpath; Viewsample. layer. shadowpath = [uibezierpath bezierpathwithrect: cgrectmake ( 0 , 0 , 400 , 400  )]. Cgpath; viewsample. layer. maskstobounds = No; viewsample. layer. shadowoffset = Cgsizemake ( 10 , 10  ); Viewsample. layer. shadowradius = 5  ; Viewsample. layer. shadowopacity =0.5  ;  //  Test 2 border Viewsample. layer. borderwidth = 2  ; Viewsample. layer. bordercolor = [[Uicolor redcolor] cgcolor];  //  Test 3 maskstobounds Uibutton * BTN = [[uibutton alloc] initwithframe: cgrectmake ( 0 , 0 , 500 , 500 )]; BTN. backgroundcolor = [Uicolor lightgraycolor];  //  [Viewsample addsubview: BTN];  //  Viewsample. layer. maskstobounds = true;  //  Test 4 Bounds  //  Viewsample. layer. bounds = cgrectmake (200,200,500,500 );  //  Test 5 Viewsample. layer. Opacity = 0.5 ; Viewsample. layer. cornerradius = 5  ;} 
This article prohibits reprinting on any website and severely condemn the worms.
This article was first published in, blog garden. Please search: blog garden-Find yourself and view the original article
The first address of this article: IOS calayer
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.