Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Objective c 拍摄非';没有渲染?_Objective C_Ios7_Uiview_Uiimage_Screenshot - Fatal编程技术网

Objective c 拍摄非';没有渲染?

Objective c 拍摄非';没有渲染?,objective-c,ios7,uiview,uiimage,screenshot,Objective C,Ios7,Uiview,Uiimage,Screenshot,假设我有一个未渲染的视图,但我想。似乎我不能使用,因为上面说: 如果当前视图尚未呈现,可能是因为它尚未出现在屏幕上,则快照视图没有可见内容 如何将UIView(例如UILabel)转换为UIImage,而无需将其添加到视图层次结构中 以下是我正在使用的代码: UILabel *label = [[UILabel alloc] init]; label.text = @"Test"; [label sizeToFit]; UIGraphicsBeginImageContextWithOption

假设我有一个未渲染的视图,但我想。似乎我不能使用,因为上面说:

如果当前视图尚未呈现,可能是因为它尚未出现在屏幕上,则快照视图没有可见内容

如何将UIView(例如UILabel)转换为UIImage,而无需将其添加到视图层次结构中

以下是我正在使用的代码:

UILabel *label = [[UILabel alloc] init];
label.text = @"Test";
[label sizeToFit];

UIGraphicsBeginImageContextWithOptions(label.bounds.size, NO, 0.0f);
[label drawViewHierarchyInRect:label.bounds afterScreenUpdates:NO];
UIImage * snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这会导致快照图像显示为黑色,正如人们所期望的那样。是否有类似于SnapshotViewAfterScreen更新:的API,允许我创建UIImage而不需要渲染视图?

据我所知,不需要在屏幕上渲染视图:

[label.layer renderInContext:UIGraphicsGetCurrentContext()];