1. Rounded corners rounded rectangles are used incisively and vividly in iOS, and have also become the iconic feature of Apple’s design. In development, we often set a view as rounded corners, and the setting method is as follows:
Self. LayerView1. Layer. The cornerRadius = 20.0 f;Copy the code
This value defaults to 0 and is a right Angle. Normally, no matter how it is set, it will not affect any of the sublayers. This is a CALayer property, not a view property, but a view can also use it. We set the rounded corners to actually set the rounded corners of the layer, and the view is a visual representation of the layer. Speaking of borders, which are common in everyday development, borderWidth defines the borderWidth in points, defaults to 0, and the default color is black,
Self. LayerView2. Layer. BorderWidth = 5.0 f; // Four parameters are red, green, blue, Alpha self. LayerView2. Layer. The borderColor = CGColorCreate (colorSpace, (CGFloat []) {0.32, 0.64, 0.96, 1.00});.Copy the code
It is used to control the display of shadows. Its value ranges from 0 to 1.0, with the default being 0 and no shadow. It also has three other parameters: shadowColor, shadowOffset and shadowRadius. Set the shadow color, the offset of the shadow, and the ambiguity of the shadow respectively, where the default color of the shadow is black, the default offset is CGSize type, the default is {0, -3}, and the default ambiguity is 0, between 0 and 1.0, the larger the ambiguity, the higher the ambiguity. The shadows we talked about above are in terms of layer borders, and the shadows on the layer inherit from the shape of the layer, so the shadows are based on the outline of the image. When we set the maskToBounds attribute to YES, it’s on the cutting out the redundant view on the outside also will be shadow to cut off, but that does not conform to our needs, in order to solve this problem, a method mentioned in the book, our layer in place, the clip on the bottom to layer wrapped him in a new layer, Add a superview to it and set the shadow of the superview so that when the shadow of the original layer is clipped, the shadow of the parent layer is the same size as the shadow of the original layer.
Everything here is not difficult, but it is not easy to understand and remember. It is best to write your own code to increase the impression.