Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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 用户单击UIButton时的图像失真_Iphone_Ios_Ios4 - Fatal编程技术网

Iphone 用户单击UIButton时的图像失真

Iphone 用户单击UIButton时的图像失真,iphone,ios,ios4,Iphone,Ios,Ios4,当我按下带有背景图像的UI按钮时,我看到一件奇怪的事情: 下面是我设置按钮的代码: NSString *path = [[NSBundle mainBundle] pathForResource:self.categoryItem.label ofType:@"jpg"]; UIImage *theImage = [UIImage imageWithContentsOfFile: path]; UIButton *imageBtn = [UIButton buttonWithType:UIB

当我按下带有背景图像的UI按钮时,我看到一件奇怪的事情:

下面是我设置按钮的代码:

NSString *path = [[NSBundle mainBundle] pathForResource:self.categoryItem.label ofType:@"jpg"];
UIImage *theImage = [UIImage imageWithContentsOfFile: path];

UIButton *imageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
imageBtn.frame = CGRectMake(0, 0, 320, 235);
[imageBtn setImage:theImage forState:UIControlStateNormal];
[imageBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];

[imageBtn addTarget:self action:@selector(onImageClick:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:imageBtn];
编辑:我很抱歉没有澄清我看到的奇怪之处——我当时正赶着下火车

问题是,当用户用背景图像单击UIButton时,图像会延伸到屏幕的宽度。它在正常状态下很好,但是点击状态是我看到失真的地方,你可以在我上面提到的屏幕录制中看到


谢谢

更改为[imageBtn.imageView设置内容模式:UIViewContentModeScaleAspectFill];请与我们分享你使用了哪个站点作为tiny url。解释起来真是太好了。请与我们分享。谢谢。@Vijay,这不是我想要的效果。您的解决方案使我的图像始终充满。我想保持健康,这样点击不会导致图像填充,但也能保持健康。哦,是的,url来自一个名为“我不明白你想要什么”的应用程序,请将你的onImageClick方法代码粘贴到这里