Ios 圆形图像视图';设置“图像”属性后,图像的边框不平滑
使用上述代码,边界平滑且很棒 但是在添加Ios 圆形图像视图';设置“图像”属性后,图像的边框不平滑,ios,swift,uiimageview,Ios,Swift,Uiimageview,使用上述代码,边界平滑且很棒 但是在添加imageView.image=UIImage(名为:“demo”) imageView的边框不再平滑。 为什么会这样 更新: layer.radius似乎有问题,在移除后,即使在imageView上设置了image属性,边界仍然平滑imageView.layer.cornerRadius=frame.size.width*0.5 更新2: 结果发现UICollectionViewCell有问题,imageView是UICollectionVie
imageView.image=UIImage(名为:“demo”)
imageView的边框不再平滑。
为什么会这样
更新: layer.radius似乎有问题,在移除后,即使在imageView上设置了image属性,边界仍然平滑
imageView.layer.cornerRadius=frame.size.width*0.5
更新2: 结果发现UICollectionViewCell有问题,imageView是UICollectionViewCell的一部分
u可以使用2个imageview 1显示图像,第二个用于隐藏和显示圆形图像 第一个图像视图按原样显示图像 第二个图像视图在第一个图像上方有白色背景和绿色圆圈,图像中间是透明的
基本上,你的图像应该是正方形的。除此之外:
class PPAvatarCollectionCell: UICollectionViewCell {
var imageView:UIImageView!
override init(frame: CGRect) {
super.init(frame: frame)
imageView = UIImageView(frame: CGRect(origin: CGPointMake(0, 0), size: CGSizeMake(frame.size.width, frame.size.height)))
self.addSubview(imageView)
imageView.contentMode = .ScaleAspectFill
imageView.backgroundColor = UIColor.whiteColor()
imageView.layer.borderColor = UIColor.greenColor().CGColor
imageView.layer.borderWidth = 10
imageView.image = UIImage(named: "demo")
imageView.layer.cornerRadius = frame.size.width*0.5
imageView.clipsToBounds = true
}
使用易于使用的扩展功能检查完整解决方案:
您是从设备上捕获的吗??你能在真正的设备上登记吗??这可能是因为您的显示器屏幕分辨率造成的。@NitinGohel在设备上也是这样。@NitinGohel@KiranI尝试过更改cornerRadius值吗?@Kiran我将半径设置为常量17,结果是samecan有人投票赞成这个问题吗?@NitinGohel@KiranI知道,但对这个问题非常好奇您的解决方案不起作用。你的代码和我的一样。您可以尝试集合视图单元格演示
imageView.layer.cornerRadius = self.frame.height / 2
imageView.layer.masksToBounds = false
imageView.clipsToBounds = true
imageView.image = "yourSquareImage"