以编程方式截取屏幕截图时,UISegmentedControl中所选段的标题消失
我有一个UISegmentedControl
添加到UIToolbar
:
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame]; toolbar.barStyle = UIBarStyleBlack; toolbar.translucent = YES; toolbar.barTintColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.0]; [self.view addSubview:toolbar]; UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Last week", @"Last month", @"All time"]; [segmentedControl setSelectedSegmentIndex:0]; [toolbar addSubview:segmentedControl];
然后将工具栏添加到视图控制器。 当我拍摄视图控制器的屏幕截图时,会发生一些奇怪的事情。 所选部分的标题消失。
屏幕截图使用:
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, [[UIScreen mainScreen] scale]); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
渲染视图:
截图:
任何关于从哪里开始寻找的指示将不胜感激。
我已经换了
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
同
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
现在它按预期工作。 仍然不明白为什么会发生这种情况。
请注意, drawViewHierarchyInRect:afterScreenUpdates:
仅适用于iOS 7。