2016-04-20 24 views
0

在iOS 9.3中,我有一个正方形的UIImageView(例如200x200),我尝试用cornerRadius指定一个UIImage(1x1像素),并且UIImageView成为一个圆。我认为这个问题来自于UIImageView的渲染。UIImageView如何在iOS 9.3渲染UIImage?

photoImageView.image = [UIImage imageNamed:@"iphone.jpeg"]; // 1px height x 1 px width 
photoImageView.contentMode = UIViewContentModeScaleToFill; 
// It can fixed with the below code 
// photoImageView.image = [[UIImage imageNamed:@"iphone.jpeg"] stretchableImageWithLeftCapWidth:2 topCapHeight:2]; 
// photoImageView.contentMode = UIViewContentModeScaleAspectFill; 
photoImageView.layer.cornerRadius = 20.0; 
photoImageView.layer.masksToBounds = YES; 

如果我改变以下9.3 contentMode到ScaleAspectFill或ScaleToFill,或更改的UIImage(2×2)的大小,或iOS版本,它就像我的预期。

http://i.imgur.com/kM36GPW.png

项目:download the sample projec

红:真正的结果。 绿色:预计。

有人可以解释它的原因吗?谢谢。

+0

set photoImageView.clipsToBounds = YES; –

回答

0

尝试通过更改角半径值

photoImageView.image = [UIImage imageNamed:@"iphone"]; // 1px height x 1 px width 
photoImageView.contentMode = UIViewContentModeScaleToFill; 
photoImageView.layer.cornerRadius = 5.0; 
photoImageView.layer.masksToBounds = YES; 
+0

即使我将cornerRadius设置为1,它仍然呈现圆圈。我可以解决这个问题,但我不知道原因,我只需要知道问题发生的原因。 –

0

设置masksToBounds = YES

photoImageView.layer.masksToBounds=YES; 

,并设置imageview的模式看点填写或看点飞度。

+0

感谢Mitesh。 我不打算得到一个圆圈UIImageView,但我有一个圆圈。我不知道为什么我有一个圈子? –

+0

为您设置另一张图像UIimageView并检查它。 photoImageView.image = [UIImage imageNamed:@“1.jpg”]; photoImageView.layer.cornerRadius = 20.0; photoImageView.layer.masksToBounds = YES;我检查你的项目和它的工作。看到这个。在你的项目中你设置了clipstobound = yes,所以imageview变成了圆形。 –

+0

Hi Mitesh,“1.jpg”的维度是什么?你在iOS 9.3上试用1x1图片吗? –