我必须添加一个UIImageView作为MapView的子视图.为此,我在MapView上创建了一个图层.在这一层,我想放置我的图像,但我得到一个白色的矩形,没有别的.我的图片不可见.
这是代码:
- (void)viewDidLoad
{
//......
CALayer *layer = [CALayer layer];
layer.backgroundColor = [[UIColor whiteColor] CGColor];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
layer.bounds = CGRectMake(self.mapView.bounds.origin.x,
self.mapView.bounds.origin.y, 80, 300);
}
else
{
layer.bounds = CGRectMake(self.mapView.frame.origin.x,
self.mapView.frame.origin.y, 150, 700);
}
layer.contents = (id)[UIImage imageNamed:@"myImage.png"];
//the name is correct but in the output the image is not visible
[[self.mapView layer] addSublayer:layer];
[layer setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud) 正如标题所说。我有一个UIImageView,并且正在将CAShapeLayers插入到视图中。问题是我不知道如何将它们插入UIImageView的图像后面。任何建议将不胜感激,谢谢。