title: round image in swift
body: <p>I'm trying to make an image round. I always used maskCircle but this time it does not work. I wrote the code in UICollectionViewCell's awakeFromNib and I can not use viewDidLayoutSubviews since I'm dequeueing the cell in cellForItemAt function. So this is the code: </p>
  
  <pre><code>@IBOutlet weak var storeLogo: UIImageView!
  override func awakeFromNib() {
      super.awakeFromNib()
      storeLogo.maskCircle()
      storeLogo.clipsToBounds = true
  }
  </code></pre>
  
  <p>and the imageView looks like this: 
  <a href="https://i.stack.imgur.com/3MSZE.png" rel="nofollow noreferrer">imageView</a></p>
  
  <p>edit: 
  it seemed to work fine, but i have the problem again.
  this is the code in awakeFromNib now: </p>
  
  <pre><code>    super.awakeFromNib()
      storeLogo.clipsToBounds = true
      storeLogo.layer.cornerRadius = storeLogo.frame.width / 2
  
      let gradient = CAGradientLayer()
      gradient.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: 55, height: 55))
      gradient.startPoint = CGPoint(x: 0, y: 1)
      gradient.endPoint = CGPoint(x: 1, y: 0)
      gradient.colors = [Color.storeName?.cgColor, Color.idTint?.cgColor]
  
      let shape = CAShapeLayer()
      shape.lineWidth = 2
      let radius: CGFloat = 27
      shape.path = UIBezierPath(roundedRect: CGRect(x: -2.5, y: -14, width: 2.0 * radius, height: 2.0 * radius), cornerRadius: radius).cgPath
      shape.position = CGPoint(x: self.frame.midX - radius, y: self.frame.midY - radius)
      shape.strokeColor = UIColor.black.cgColor
      shape.fillColor = UIColor.clear.cgColor
      gradient.mask = shape
  
      self.storeLogo.layer.addSublayer(gradient)
  </code></pre>
  
  <p>and the image is not round as you can see in this image: <a href="https://i.stack.imgur.com/cRr9n.png" rel="nofollow noreferrer">imageView</a>
  i</p>
  
  <p>i don't know why the image is not a circle now. any idea?!</p>