我试着用下面的代码截图UIView
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
但是UISegmentControl's
选择的文本存在问题。它只出现在IOS7中。完美的工作与<=IOS6.
,我附了屏幕截图。
IOS 6屏幕截图,运行良好.
,但相同的代码不适用于IOS7+.
如果有人找到解决办法或原因,请帮助我。
发布于 2014-05-19 08:37:11
最后,我找到了解决方案,但我不知道,它是如何工作的(这背后的概念)。但假设是,图层渲染将发生在动画结束。但是drawViewHierarchyInRect:
将呈现显示的绝对屏幕。我的代码如下。
#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.的推荐信
发布于 2014-05-19 07:23:40
请你试一下这个答案:
在这个答案中,我试图改变SegmentController
的字体颜色。
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];
https://stackoverflow.com/questions/23731071
复制相似问题