尝试在Swift中制作圆形UIView时出错

克劳斯

我的屏幕布局中有一个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

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

埃尔辛·塞金(Ersin Sezgin)

你可以试试这个吗

//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;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章