本文介绍了以编程方式拍摄屏幕快照时,UISegmentedControl中选定段的标题消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在UIToolbar
中添加了UISegmentedControl
:
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];
然后将工具栏添加到视图控制器.当我截取视图控制器的屏幕截图时,发生了一些奇怪的事情.所选段的标题消失.
The toolbar is then added to a view controller. When I take a screenshot of the view controller, something weird happens. The title of the selected segment disappears.
正在使用以下屏幕截图:
The screenshot is being taken using:
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];
现在它可以按预期运行.仍然不明白为什么会这样.
And now it works as expected. Still don't understand why that happens though.
请注意,drawViewHierarchyInRect:afterScreenUpdates:
仅是iOS 7.
Note that drawViewHierarchyInRect:afterScreenUpdates:
is iOS 7 only.
这篇关于以编程方式拍摄屏幕快照时,UISegmentedControl中选定段的标题消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!