我的屏幕布局中有一个 UIImageView,它会根据容器 View 尺寸动态调整大小。我想在圆形 View 中转换它,我正在使用以下代码:
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
问题是生成的 View 并不总是圆形的。为了实现这种效果,我必须在 iPhone 4 上将 dSize
除以 2.0,在 iPhone 5/5s 上除以 1.7,在 1.5 在 iPhone 6/6s 上。我不知道我做错了什么。
最佳答案
你能试试这个吗
//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;
关于ios - 尝试在 Swift 中制作圆形 UIView 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30667875/