首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >图层截图不接受UISegmentControl选定的文本

图层截图不接受UISegmentControl选定的文本
EN

Stack Overflow用户
提问于 2014-05-19 06:33:21
回答 2查看 61关注 0票数 1

我试着用下面的代码截图UIView

代码语言:javascript
运行
复制
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是UISegmentControl's选择的文本存在问题。它只出现在IOS7中。完美的工作与<=IOS6.,我附了屏幕截图。

IOS 6屏幕截图,运行良好.

,但相同的代码不适用于IOS7+.

如果有人找到解决办法或原因,请帮助我。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-19 08:37:11

最后,我找到了解决方案,但我不知道,它是如何工作的(这背后的概念)。但假设是,图层渲染将发生在动画结束。但是drawViewHierarchyInRect:将呈现显示的绝对屏幕。我的代码如下。

代码语言:javascript
运行
复制
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define iOS7_0 @"7.0"

UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(iOS7_0))
    [baseView drawViewHierarchyInRect:baseView.frame afterScreenUpdates:YES];
else
    [baseView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

我看到了this post.的推荐信

票数 0
EN

Stack Overflow用户

发布于 2014-05-19 07:23:40

请你试一下这个答案:

在这个答案中,我试图改变SegmentController的字体颜色。

代码语言:javascript
运行
复制
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                        [UIFont boldSystemFontOfSize:14], UITextAttributeFont,
                        [UIColor redColor], UITextAttributeTextColor,
                        nil];
[yoursegmentedControl setTitleTextAttributes:dic forState:UIControlStateNormal];
NSDictionary *clickedindex= [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[yoursegmentedControl setTitleTextAttributes:clickedindex forState:UIControlStateHighlighted];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23731071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档