Ios UIImageView无法显示CALayer的内容?

Ios UIImageView无法显示CALayer的内容?,ios,uiimageview,uiimage,calayer,Ios,Uiimageview,Uiimage,Calayer,在UILabel显示后,我可以看到下划线层的内容不是零。然后我会这样做: UIImage *image = [UIImage imageWithCGImage:(__bridge CGImageRef)(self.v2.layer.contents)]; UIImageView *iv = [[UIImageView alloc] initWithImage:image]; iv.backgroundColor = [UIColor grayColor]; iv.frame = CGRectMa

在UILabel显示后,我可以看到下划线层的内容不是零。然后我会这样做:

UIImage *image = [UIImage imageWithCGImage:(__bridge CGImageRef)(self.v2.layer.contents)];
UIImageView *iv = [[UIImageView alloc] initWithImage:image];
iv.backgroundColor = [UIColor grayColor];
iv.frame = CGRectMake(100, 200, 120, 120);
[self.window addSubview:iv];
但我看不到图像,为什么?我可以看到图像视图就在那里,只是背景颜色为灰色。

因为当您使用contents属性作为getter时,CALayer不会返回CGImageRef。 记录返回值,您将看到,您得到了一个在iOS 6中测试的CABackingStore实例

// label is a UILabel
NSLog(@"%@", self.label.layer.contents);
// NSLog output : <CABackingStore 0x7181b90 (buffer [126 21] BGRA8888)>

我想你是对的,但是我能得到后备商店的图片吗?@KarlPeng不,你不能,CABackingStore是一个私有类。@KarlPeng如果你想把一个CALayer画进一个图片上下文中,对它进行一点研究就会给你答案。
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(100, 200, 120, 120)];
iv.backgroundColor = [UIColor grayColor];
iv.layer.contents = self.v2.layer.contents;
[self.window addSubview:iv];