When i compute the radius with the width of the UIImageView divide by 2 i obtain that.
In the storyboard the size of my UIImageView is 64x64
with a radius computed with a width / 2
Here s my code (Image is my custom class used with the library FastImageCash):
let image = Image(identifier: fileinfo.identifier, weburl: weburl, fileurl: fileinfo.fileurl)
image.loadImage()
let rect = CGRectMake(0.0, 0.0, imgUser.frame.size.width, imgUser.frame.size.height)
let sizeImage = image.img!.size ?? CGSizeZero
let ratioW = sizeImage.width / rect.width
let ratioH = sizeImage.height / rect.height
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
let radius = CGFloat(rect.width / 2.0)
let circle = UIBezierPath(arcCenter: CGPointMake(rect.width / 2, rect.height / 2), radius: radius, startAngle: CGFloat(0.degreesToRadians), endAngle: CGFloat(360.degreesToRadians), clockwise: true)
circle.lineWidth = CGFloat(1.0)
circle.addClip()
var area = CGRect()
let ratio = ratioW > ratioH ? ratioW : ratioH
area.size.height = sizeImage.height / ratio
area.size.width = sizeImage.width / ratio
area.origin.x = (rect.height - area.size.height) / 2
area.origin.y = (rect.width - area.size.width) / 2
image.img?.drawInRect(area)
let thumb = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
imgUser.image = thumb
I don't understand why it works if i compute the radius with
...
let radius = CGFloat(rect.width / 2.5)
...