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)


    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转载自:https://github.com/Tim9Liu9/TimLiu-iOS[https://github...
    香橙柚子阅读 8,715评论 0 36
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,229评论 4 61
  • 双母镇是个依山不傍水的偏远小镇,双母镇不大,谁家出了什么事,三天就从镇东头传到了镇西。大武是镇上出名的小混混:喝酒...
    半理阅读 321评论 0 1
  • 我在看考研政治书 好笑吗?不好笑 我看的还挺认真的。挺投入的,人真是可以无限可能
    haoharriet阅读 79评论 0 1
  • 容器的概念所谓STL容器,即是将最常运用的一些数据结构(data structures)实现出来。容器是指容纳特定...
    饭饭H阅读 391评论 0 0