How can i make i circle picture with swift ?
My ViewController :
import UIKit import Foundation class FriendsViewController : UIViewController{ @IBOutlet weak var profilPicture: UIImageView! override func viewDidLoad() { super.viewDidLoad() profilPicture = UIImageView(frame: CGRectMake(0, 0, 100, 100)) } }
My profilPicture = UIImageView(frame: CGRectMake(0, 0, 100, 100))
do nothing ..
Exemple: http://www.appcoda.com/ios-programming-circular-image-calayer/
Implementing the Round Image Section To do this, first add the viewWillAppear method inside the viewcontroller. swift file as shown below. after doing it, we will first call the image with its name and then later we can set the corner radius and also the cliptobound to true to make the round image as shown below.
ImageView can be defined as an object that can display the images on the interface of the iOS applications. It is the instance of the UIImageView class, which inherits UIView.
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.black.cgColor image.layer.cornerRadius = image.frame.height/2 image.clipsToBounds = true }
If you want it on an extension
import UIKit extension UIImageView { func makeRounded() { self.layer.borderWidth = 1 self.layer.masksToBounds = false self.layer.borderColor = UIColor.black.cgColor self.layer.cornerRadius = self.frame.height / 2 self.clipsToBounds = true } }
That is all you need....
You can simple create extension:
import UIKit extension UIImageView { func setRounded() { let radius = CGRectGetWidth(self.frame) / 2 self.layer.cornerRadius = radius self.layer.masksToBounds = true } }
and use it as below:
imageView.setRounded()
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