2011-06-03 49 views
2

我有一個圓形的圖像80個單位的80個單位,並嘗試使用的UIImageView的contentstretch屬性,將其更改成丸狀,但我只能得到一個橢圓形。有任何想法嗎?這裏是我的代碼:的UIView contentstretch改變一圈橢圓形,而不是藥丸形狀

imageView.frame = CGRectMake(0,0,80,80); 
imageView.layer.contents = (id)([UIImage imageNamed:@"circle.png"]).CGImage; 
imageView.contentStretch = CGRectMake(0.5, 0,0, 1); 
[UIView animateWithDuration:0.5 delay: 0.0 options: UIViewAnimationOptionTransitionNone 
animations:^{ 
    imageView.frame = CGRectMake(imageView.frame.origin.x,imageView.frame.origin.y, imageView.frame.size.width+50, imageView.frame.size.height); 
     } 
     completion:^(BOOL finished){ 

          }]; 
+1

奇怪。假如你想要一箇中間的矩形,你的代碼可以正常工作。是否有任何其他圖像視圖設置,你已經改變。我直接從IB使用它。 – 2011-06-03 19:05:23

+0

我只是一個品牌的新的圖像視再次嘗試。我不設置任何其他。它變成了一個橢圓形。 – prostock 2011-06-03 19:42:55

+0

您可以檢查['this'(http://dl.dropbox.com/u/22783696/CircleStretch.zip)出來。 – 2011-06-03 19:48:49

回答

0

你試過了嗎?

UIImage *circleImage = [UIImage imageNamed:@"circle.png"]; 
UIImage *stretchImage = [circleImage stretchableImageWithLeftCapWidth:40 topCapHeight:40]; 
imageView.image = stretchImage;