I managed to draw a rect :-) But I don't know how to draw a rounded rect.
Can someone help me out with the following code how to round the rect?
let canvas = UIGraphicsGetCurrentContext()
rec = CGRectMake(0, 0, 40, 40);
//var maskPath = UIBezierPath(roundedRect: rec, byRoundingCorners: .BottomLeft | .BottomRight, cornerRadii: CGSize(width: 3, height: 3))
CGContextAddRect(canvas, rec);
CGContextFillPath(canvas);
Swift 4
iOS 11
@muku answer in Swift 4.x+:
//Put this code in ur drawRect
Objective - C
Swift 3
SWIFT 3.x + 4.0 I've modified the example for Swift 3 and added few lines to centralise the rectangle in the UIView
Full code with screenshots is available on: http://lab.dejaworks.com/uiview-with-rounded-background-designable-in-storyboard/
How to create a rounded corner rectangle using BezierPath
Or for an example with values: