I've been using UIGraphicsBeginImageContextWithOptions()
and I noticed that the last field in that method is a scalefactor
. And the apple docs says, if I want to set it to 0.0, then it will use the default scale factor of the device's main screen. Is there a way to get that default scale factor via property or method?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The device's scale factor is a property of UIScreen
. You can obtain it by:
[UIScreen mainScreen].scale;
Documentation here.
回答2:
Swift 3+ version:
UIScreen.main.scale
回答3:
Hope it will help you
CGSize textcontent =CGSizeMake(width, height);
UIGraphicsBeginImageContext(textcontent);
if ([UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0f)
{
UIGraphicsBeginImageContextWithOptions(textcontent, YES, 1.0f);
}
else
{
UIGraphicsBeginImageContext(textcontent);
}
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;