我有这个 UIButton,他有一个图像,在普通 iPhone 上它工作正常,图像 contentMode 设置为 UIViewcontentModeCenter 并且它很好。但在视网膜上,图像不在中心,它很大并且不适合按钮框架。
为什么会这样,我该如何解决?
[theImageView setImage:Image forState:UIControlStateNormal];
[theImageButton setImage:Image forState:UIControlStateHighlighted];
[theImageButton setImage:Image forState:UIControlStateSelected];
[theImageButton setBackgroundColor:[UIColor clearColor]];
[theImageButton addTarget:self action:@selector(dismissKeyboard:) forControlEvents:UIControlEventAllTouchEvents];
theImageButton.imageView.contentMode = UIViewContentModeCenter;
图片加载:
- (UIImage *)loadScreenShotImageFromDocumentsDirectory
{
UIImage * tempimage;
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/MeasureScreenShot.png", docDirectory];
tempimage = [[UIImage alloc] initWithContentsOfFile:filePath];
return tempimage;
}
我不得不说,加载到 contentMode 中的图像是一个以编程方式拍摄的屏幕截图。也许它与它有关(无论如何在正常显示上它工作正常)。
谢谢!