【发布时间】:2014-03-13 22:42:58
【问题描述】:
我在UINavigationBar 中有一个UISegmentedControl,看起来像这样:
在这里您可以看到它在 Storyboard 中的创建方式:
问题是,当我以编程方式创建屏幕截图时,为了分享它,我得到了 UISegmentedControl 没有所选标签的文本,如下所示:
据我所知,状态栏不出现是正常的,并且共享按钮显示为选中状态,因为实际上它是在截屏时选中的,但不知道发生了什么UISegmentedControl,有什么想法吗?
PS:我可以分享截图代码,但它是非常简单的标准代码。
更新
这是我正在使用的屏幕截图代码:
- (UIImage*)screenshot
{
// Create a graphics context with the target size
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
{
// -renderInContext: renders in the coordinate space of the layer,
// so we must first apply the layer's geometry to the graphics context
CGContextSaveGState(context);
// Center the context around the window's anchor point
CGContextTranslateCTM(context, [window center].x, [window center].y);
// Apply the window's transform about the anchor point
CGContextConcatCTM(context, [window transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
-[window bounds].size.width * [[window layer] anchorPoint].x,
-[window bounds].size.height * [[window layer] anchorPoint].y);
// Render the layer hierarchy to the current context
[[window layer] renderInContext:context];
// Restore the context
CGContextRestoreGState(context);
}
}
// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
更新 2
这里是一个重现错误的简单项目:https://github.com/apascual/APSegmentedControlExample
【问题讨论】:
-
你试过我更新的答案了吗?
标签: ios ios7 uinavigationbar screenshot uisegmentedcontrol