尝试在Swift中创建循环UIView时出错

Cla*_*aus 1 iphone cornerradius uiview ios swift

我的屏幕布局中有一个UIImageView,它根据容器视图尺寸动态调整大小.我想在圆形视图中转换它,我使用以下代码:

let dSize: CGFloat = min(imageview.frame.height, imageview.frame.width)
imageview.frame = CGRectMake(0, 0, dSize, dSize)
imageview.clipsToBounds = true
imageview.layer.cornerRadius = dSize/2.0
imageview.layer.borderWidth = 1.0
imageview.layer.borderColor = UIColor.whiteColor().CGColor
Run Code Online (Sandbox Code Playgroud)

问题是结果视图并不总是循环的.为了实现我不得不分割效果dSize2.0 iPhone 4上,由1.7 iPhone上5/5秒和通过1.5 iPhone上的6/6秒.我无法弄清楚我做错了什么.

Ers*_*gin 5

你能试试吗?

//To make your imageView circular
imageView.layer.cornerRadius = imageView.frame.size.height/2;
imageView.layer.masksToBounds = YES;

//To add border
imageView.layer.borderColor = [UIColor whiteColor].CGColor;
imageView.layer.borderWidth = 2;
Run Code Online (Sandbox Code Playgroud)