0

我有一个带有文本、标签和 Uisegmented 按钮的屏幕。我想拍摄屏幕的完整快照并保存为图像。

这是代码。

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*theImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData*theImageData=UIImageJPEGRepresentation(theImage, 1.0 ); //you can use PNG too
[theImageData writeToFile:@"example.jpeg" atomically:YES];

但是在 Uisegmented 按钮中选择的选项显示为填充不透明。我已将 UIGraphicsBeginImageContextWithOptions 中的第二个参数更改为 false。我仍然看到它充满了。我有什么遗漏吗?

这是图像。在此处输入图像描述

4

1 回答 1

0

这个问题似乎特定于UISegmentedControl班级。我不知道为什么会这样,但是像下面这样的东西应该可以解决问题。

[segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} forState:UIControlStateNormal];

也许这些信息将有助于您进一步调查问题。

于 2014-03-27T16:01:48.350 回答