There isn't such a function, but you can do your custom drawing by overriding the draw(_ rect: CGRect) method.
A quick example of filling a view with squares of size elementSize
with blues of decreasing transparency from left to right.
override func draw(_ rect: CGRect) {
let elementSize: CGFloat = 5
let context = UIGraphicsGetCurrentContext()!
for y in stride(from: 0.0, to: rect.height, by: elementSize) {
for x in stride(from: 0.0, to: rect.width, by: elementSize) {
let color = UIColor.blue.withAlphaComponent(x / rect.width)
context.setFillColor(color.cgColor)
context.fill(CGRect(x: x, y: y, width: elementSize, height: elementSize))
}
}
}
This is how it looks:
If you want to know the ratio between a pixel and a point, you can use the screen's scale property UIScreen.main.scale or compare the screen's nativeBounds with it's bounds.
Also, consider this: