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