How to set image in circle in swift

前端 未结 14 1733
星月不相逢
星月不相逢 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:08

    // code to make the image round
    
    
    import UIKit
    
    extension UIImageView {
    public func maskCircle(anyImage: UIImage) {
    
    
        self.contentMode = UIViewContentMode.ScaleAspectFill
        self.layer.cornerRadius = self.frame.height / 2
        self.layer.masksToBounds = false
        self.clipsToBounds = true
    
    
    
    
        // make square(* must to make circle),
        // resize(reduce the kilobyte) and
        // fix rotation.
        //        self.image = prepareImage(anyImage)
    }
    }
    

    // to call the function from the view controller

    self.imgCircleSmallImage.maskCircle(imgCircleSmallImage.image!)
    

提交回复
热议问题