From the below code I got only oval shaped image I don't know why and what I did wrong..?
self.viewCirlce.layer.cornerRadius = self.viewCirlce.frame.size.width / 2
self.viewCirlce.clipsToBounds = true
From the below code I got only oval shaped image I don't know why and what I did wrong..?
self.viewCirlce.layer.cornerRadius = self.viewCirlce.frame.size.width / 2
self.viewCirlce.clipsToBounds = true
This code used to display the circle image
image.layer.borderWidth = 1
image.layer.masksToBounds = false
image.layer.borderColor = UIColor.blackColor().CGColor
image.layer.cornerRadius = image.frame.height/2
image.clipsToBounds = true
My guess would be that the component you have called viewCirlce is a rectangle to start with, you are just setting the corner radius. If the component has the same width and height then this could give you a circle. If it's a rectangle, then you'll get an ellipse.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var image: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
image.layer.borderWidth = 1
image.layer.masksToBounds = false
image.layer.borderColor = UIColor.blackColor().CGColor
image.layer.cornerRadius = image.frame.height/2
image.clipsToBounds = true
}
add this code and make sure your viewCirlce is a square view
self.viewCirlce.layer.masksToBounds = true
Make sure height and width of viewCirlce are equal and put your this code in a method which is called after viewCirlce is loaded for e.g :
override func viewDidLayoutSubviews() {
self.viewCirlce = self.viewCirlce.frame.size.height / 2.0
self.viewCirlce.layer.masksToBounds = true
}