I have this code for UIVIew
:
override func drawRect(rect: CGRect) {
let toolbarSize = CGFloat(UIDevice.currentDevice().userInterfaceIdiom == .Pad ? 0 : 54)
let width = CGRectGetWidth(self.frame)
let height = CGRectGetHeight(self.frame) - toolbarSize
let heightSpan = floor(height / 2 - self.cropSize.height / 2)
let widthSpan = floor(width / 2 - self.cropSize.width / 2)
// fill outer rect
UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).set()
UIRectFill(self.bounds)
// fill inner border
UIColor(red: 1, green: 1, blue: 1, alpha: 0.5).set()
UIRectFrame(CGRectMake(widthSpan - 2, heightSpan - 2, self.cropSize.width + 4,
self.cropSize.height + 4))
// fill inner rect
UIColor.clearColor().set()
UIRectFill(CGRectMake(widthSpan, heightSpan, self.cropSize.width, self.cropSize.height))
}
This draws a rect with a white border to my UIView
, I want to add a corner radius to draw a circle.
Is it possible to do this?
this works nice for me
someImageView.layer.borderWidth = 1
someImageView.layer.borderColor = UIColor.blackColor().CGColor
someImageView.layer.cornerRadius = someImageView.frame.height/2
someImageView.clipsToBounds = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With