I want to draw a rectangle in Swift3 and draw based on the battery level of the phone for example, if battery is 100% then rectangle must be filled completely. If battery is 67% then fill should be 67% of that rectangle's width.
I am quite new to the CGRect library and drawing.
Here is my attempt so far:
let layer = CAShapeLayer()
layer.path = UIBezierPath(roundedRect: CGRect(x: battery.frame.origin.x,
y: battery.frame.origin.y,
width: (battery.image?.size.width)!,
height: (battery.image?.size.height)!),
cornerRadius: 0).cgPath
layer.fillColor = UIColor.red.cgColor
view.layer.addSublayer(layer)
battery icon is basically already there on the page with just the border for example in the following shape:
------
| |
------