UIView fill with color and leave a empty square in center
Create a UIView that fill with color, and leave an empty in center.
This can be accomplish by using CAShapeLayer
.
1 | // 1 |
- Initialize a bezier path filled with the whole UIView
- Create another bezier path to represent the rectangle inside. Then merge the inner rectangle to the outer rectangle.
For usesEvenOddFillRule you can read more in apple doc - Create a layer (
CAShapeLayer
is subclass ofCALayer
), set the path create just now to the layer, then fill it with a color (put whatever color that you like) - Add the layer to the UIView layer (by default, all
UIView
s come with a layer)
References: