Cut a UIImage into a circle

后端 未结 11 2279
面向向阳花
面向向阳花 2020-11-27 13:30

I want to cut a UIImage into a circle so that I can then use it as an annotation. Every answer on this site that I\'ve found describes creating an UIImage

11条回答
  •  一生所求
    2020-11-27 14:05

    swift 3 conform to MVC pattern create an external file

    @IBDesignable
    class RoundImage: UIImageView{
    
    
    @IBInspectable var cornerRadius: CGFloat = 0 {
        didSet{
            self.layer.cornerRadius = cornerRadius
        }
    }
    
    // set border width
    @IBInspectable var borderWidth: CGFloat = 0 {
        didSet{
            self.layer.borderWidth = borderWidth
        }
    }
    
    // set border color
    
    @IBInspectable var borderColor: UIColor = UIColor.clear {
        didSet{
            self.layer.borderColor = borderColor.cgColor
        }
    }
    
    override func awakeFromNib() {
        self.clipsToBounds = true
    }
    
    
    }// class
    

    call class in the IB on storyboard

    set cornerradius as you please (1/2 of width if desire circle)

    Done!

提交回复
热议问题