How to set image in circle in swift

前端 未结 14 1726
星月不相逢
星月不相逢 2020-12-04 09:55

How can i make i circle picture with swift ?

My ViewController :

import UIKit
import Foundation

class FriendsViewController : UIViewController{

            


        
14条回答
  •  攒了一身酷
    2020-12-04 10:20

    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....

提交回复
热议问题