Shapes
We can round an object's borders by doing the following:
button.layer.cornerRadius = (amount to round)
This means that we don't need alpha'd circles or rounded objects, as a simple .jpg is enough. The result is a lighter and faster app.
In theory, we can do any shape. However, depending on time, and how this shape is used, it might be better to have it as an asset.
This is how to do a triangle:
class TriangleView : UIView {
override func draw(_ rect: CGRect) {
guard let context = UIGraphicsGetCurrentContext() else { return }
context.beginPath()
context.move(to: CGPoint(x: rect.minX, y: rect.maxY))
context.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
context.addLine(to: CGPoint(x: (rect.maxX / 2.0), y: rect.minY))
context.closePath()
context.setFillColor(red: 1.0, green: 0.5, blue: 0.0, alpha: 0.60)
context.fillPath()
}
}
A lot weirder, right? The more sides, the longer the code will be. In cases like this, we should talk and see what is the better option.
Last updated