Set order on displaying paths/images

2019-04-17 17:09发布

问题:

I have a couple of arcs and rects in a UIView, and a UIImageView as well. I want to have the UIImageView in the background. I have ordered it in IB so that the image view is behind my labels and buttons.

First, I need to put an image in the image view, which I don't want to do in IB. I've tried this code

UIImage *myImage = [UIImage imageNamed:@"image.png"];
UIImageView *myImageView = [[UIImageView alloc] initWithImage:@"myImage"];

But it doesn't work. After I get that working, what can I do to move my paths in front of the image view?

回答1:

Add image to UIImageView :

UIImage *myImage = [UIImage imageNamed:@"image.png"];
UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];
[self.view addSubview:myImageView];


回答2:

I think you want to draw to put a background image and on top of it want to draw circles(arcs).

If my understanding is correct. First draw the image on to the view using CGContextDrawImage() and then draw arcs on top of it. (No need to use image view).