Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIView contentstretch将圆更改为椭圆形,而不是丸形_Iphone_Objective C - Fatal编程技术网

Iphone UIView contentstretch将圆更改为椭圆形,而不是丸形

Iphone UIView contentstretch将圆更改为椭圆形,而不是丸形,iphone,objective-c,Iphone,Objective C,我有一个80个单位乘80个单位的圆形图像,并试图使用UIImageView的contentstretch属性将其更改为药丸形状,但我只能得到一个椭圆形。有什么想法吗?这是我的密码: imageView.frame = CGRectMake(0,0,80,80); imageView.layer.contents = (id)([UIImage imageNamed:@"circle.png"]).CGImage; imageView.contentStretch = CGRectMake(0.5

我有一个80个单位乘80个单位的圆形图像,并试图使用UIImageView的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){

                             }];
你试过了吗

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

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

奇怪的当我尝试的时候,你的代码工作正常,假设你想要一个中间的矩形。您是否更改了其他图像视图设置。我是直接从IB开始使用它的。我只是用一个全新的图像视图再试一次。我没有设置任何其他内容。它只是变成了一个椭圆形。你可以查看.thx来计算它。可能是因为我的图像大小不完全是80像素,导致了这个问题。当我尝试的时候,你的代码工作正常,假设你想要一个中间的矩形。您是否更改了其他图像视图设置。我是直接从IB开始使用它的。我只是用一个全新的图像视图再试一次。我没有设置任何其他内容。它只是变成了一个椭圆形。你可以查看.thx来计算它。可能是我的图像大小不完全是80像素造成的问题