Search code examples
objective-caddsubview

Adding a subview between some objects


I have a scrollview in my view controller.

I'm adding a subview

UIImageView *IMG1 = [[UIImageView alloc] init];
IMG1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IMAGE.png"]];
[self.view addSubview:IMG1];
IMG1.frame = CGRectMake(20, 20, 35, 35);

So the question is how to add it under my scroller (between scroller and my view)?


Solution

  • Move this content to ViewDidLoad and add the scrollView after imageView

    -(void) viewDidLoad
    {
    [super viewDidLoad]
    
    UIImageView *IMG1 = [[UIImageView alloc] init];
    IMG1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IMAGE.png"]];
    [self.view addSubview:MySubImage];
    IMG1.frame = CGRectMake(20, 20, 35, 35);
      [self.view sendSubviewToBack:IMG1];
    //// add your scrollView and subViews 
    }