Swift - 生成圆形头像

Swift - 生成圆形头像

    func createIcon() {
        let photo = UIImageView()
        let image = UIImage(named:icon)
        let imageSize:CGFloat = 75.0 * 2
        
        photo.bounds = CGRectMake((self.view.bounds.size.width-imageSize)/2, (self.view.bounds.size.height-imageSize)/2-150, imageSize, imageSize)
        photo.frame = CGRectMake((self.view.bounds.size.width-imageSize)/2, (self.view.bounds.size.height-imageSize)/2-150, imageSize, imageSize)
        // 用设置圆角的方法设置圆形
        photo.layer.cornerRadius = CGRectGetHeight(photo.bounds)/2
        
        // 设置图片的外围圆框*
        photo.layer.masksToBounds = true
        photo.layer.borderColor = UIColor.whiteColor().CGColor
        photo.layer.borderWidth = 3
        
        photo.image = image
        self.view.addSubview(photo)


    }

你可能感兴趣的:(Swift - 生成圆形头像)