Objective c 视网膜显示的图像内容模式问题
我有一个UIButton,他有一个图像,在普通的iPhone上可以正常工作,图像内容模式设置为UIViewcontentModeCenter,很好。但在视网膜上,图像不是中央,它很大,不适合按钮框 这是为什么?我该如何修复它Objective c 视网膜显示的图像内容模式问题,objective-c,ios,uibutton,retina-display,Objective C,Ios,Uibutton,Retina Display,我有一个UIButton,他有一个图像,在普通的iPhone上可以正常工作,图像内容模式设置为UIViewcontentModeCenter,很好。但在视网膜上,图像不是中央,它很大,不适合按钮框 这是为什么?我该如何修复它 [theImageView setImage:Image forState:UIControlStateNormal]; [theImageButton setImage:Image forState:UIControlStateHighlighted]; [theImag
[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的图像是一个通过编程方式拍摄的屏幕截图。也许这与它有关(无论如何,在正常的显示器上,它工作得很好)
谢谢 听起来你得到的是一张视网膜图像,比例为1.0。您需要告诉系统,您的图像实际上是2.0,如果您使用上下文捕获屏幕截图,请使用
UIGraphicsBeginImageContextWithOptions(..., ..., 0.0);
0.0
告诉它使用当前设备的主屏幕比例,或者您可以自己指定正确的比例。@rckoenes我已经编辑了我的问题,请看一看。仍然缺少如何加载图像。@rckoenes好的,现在您可以检查它。演示如何获取图像?