Here's the code:
main.swift2889 chars74 lines
This code defines a UnionJackView
class that inherits from UIView
. The draw()
method of this class is called when the view is displayed on screen. This method draws the Union Jack flag three times, with different sizes and positions.
The actual drawing is done using CAShapeLayer
and UIBezierPath
. The drawUnionJack()
method takes a size
and an origin
as parameters, and creates a new CAShapeLayer
that contains the flag. It then adds sublayers to this layer to draw the red and white rectangles, the red cross, and the white lines that intersect in the center.
The createRectLayer()
method is a helper method that creates a CAShapeLayer
for a rectangular path with the given rect
and color
.
To use this view, simply instantiate a UnionJackView
and add it to your view hierarchy. For example:
main.swift67 chars3 lines
gistlibby LogSnag