Ответ 1
Решение состоит в том, чтобы изменить надпись labelScale до 2, прежде чем вы его нарисуете, а затем сразу же установите его обратно. Я просто закодировал проект, чтобы проверить его, и его работа прекрасна, создавая 2x изображение в обычном телефоне сетчатки (симулятор). [Если у вас есть общественное место, я могу сказать, что дайте мне знать.]
РЕДАКТИРОВАТЬ: расширенный код перемещает подзоны и любые контейнеры UIViews для установки/отмены шкалы
- (IBAction)snapShot:(id)sender
{
[self changeScaleforView:snapView scale:2];
UIGraphicsBeginImageContextWithOptions(snapView.bounds.size, snapView.opaque, 2);
[snapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageDisplay.image = img; // contentsScale
imageDisplay.contentMode = UIViewContentModeScaleAspectFit;
[self changeScaleforView:snapView scale:1];
}
- (void)changeScaleforView:(UIView *)aView scale:(CGFloat)scale
{
[aView.subviews enumerateObjectsUsingBlock:^void(UIView *v, NSUInteger idx, BOOL *stop)
{
if([v isKindOfClass:[UILabel class]]) {
v.layer.contentsScale = scale;
} else
if([v isKindOfClass:[UIImageView class]]) {
// labels and images
// v.layer.contentsScale = scale; won't work
// if the image is not "@2x", you could subclass UIImageView and set the name of the @2x
// on it as a property, then here you would set this imageNamed as the image, then undo it later
} else
if([v isMemberOfClass:[UIView class]]) {
// container view
[self changeScaleforView:v scale:scale];
}
} ];
}