如何在swift 4中使图像视图圆形 [英] How to make image view round in swift 4

查看:35
本文介绍了如何在swift 4中使图像视图圆形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然互联网上有这个问题的解决方案,但我无法这样做,我想对图像进行四舍五入.

Though there is solution of this question is present in internet, but I am unable to do so, I want to round a image.

我正在使用的代码:

extension UIImageView {        
    func makeRounded() {
        let radius = self.frame.width/2.0
        self.layer.cornerRadius = radius
        self.layer.masksToBounds = true
    }
 }

然后我在 viewdidload() 中调用这个函数,就像 imgvw.makeRounded().但它不会到来.请帮忙

then i call this function in viewdidload() like imgvw.makeRounded(). but it is not coming. please help

上一个链接对我没有帮助

the previous link is not helping me

推荐答案

import UIKit

class ViewController: UIViewController {
  @IBOutlet weak var image: UIImageView!

  func makeRounded() {

    image.layer.borderWidth = 1
    image.layer.masksToBounds = false
    image.layer.borderColor = UIColor.blackColor().CGColor
    image.layer.cornerRadius = image.frame.height/2 //This will change with corners of image and height/2 will make this circle shape
    image.clipsToBounds = true
}

快乐编码

这篇关于如何在swift 4中使图像视图圆形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆