Calayer is a relatively underlying class. Each uiview contains a uilayer attribute (you can also see this attribute when you click uiview ). Before use, you need to import the quartzcore framework, and then set the calayer to reference the header file quartzcore. h.
1. Simple uiview Processing
Next, we will introduce several common features:
1) rounded corners:
2) Border:
3) shadow:
2. More layers of processing.
The above three methods are simple and crude to directly solve the problem.
Is it possible to set all the rounded corners, borders, or shadows with this?
Next, let's look at another example. What we will inevitably encounter is processing the rounded corner of the image. We try to use the first one above to process the image.
1) set image rounded corners
In this case, is there a situation we mentioned above? Is the image rounded?
If you try the code yourself, you will find it strange that this is not the case, and the picture is still as it is. So why?
The reason is that there are more than one imageview layer. Although we have set a rounded corner for this layer, we have only processed the parent layer, but the image above is still not processed. In this case, we need to introduce a professional term in IOS called "mask ". See the following code.
[Imageview. layer setmaskstobounds: Yes];
At this time, we will find that our image has been rounded. This "mask" is used to make all views change with the layer of the top view.
2) set the image border
As with the rounded corner set above, it can be displayed normally.
3) set the Image Shadow.
We will find that at this time, although we have set a "mask", there is still no shadow.
However, if we comment out the "mask", The Image Shadow will appear.
After checking the information, we found that this is actually an imperfect part of Apple's processing, so that we need to make a trade-off between the shadow and the rounded corner when using it, is shadow used or rounded corner used? Of course, this is based on the customer's needs. If the customer wants to achieve both the rounded corner and the shadow, we can only cooperate with the UI Designer.
Iii. How to Use calayer to set deformation
The deformation here refers to the changes in the uiview, such as the enlargement and reduction of imagev and the rotation.
This learning can deepen our understanding of animation content.
Directly run the Code:
Imageview deformation can be implemented here.
We can also use the principle of KVC amplitude to set it:
It can still be implemented normally. Here we can see the high level of KVC.
This is calayer's knowledge. If you have other ideas, I hope you can correct them.
What are the actual usage of calayer?