I have a picture. I have a program for iPhone. How to write a method that would set a picture (class UIImage ) on top of everything else?

Note: you need to fill the entire screen with a picture.

Closed due to the fact that the essence of the question is incomprehensible to the participants of Streletz , rjhdby , cheops , Kirill Stoianov , HamSter on Oct 13 '16 at 5:41 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Uh, guys, why does the question require editing? Who does not understand the essence of the question here, when as many as three people gave quite correct and acceptable answers? Almost all the respondents correctly understood the essence of the question. - Andrew Kachalin

4 answers 4

If I understand the question correctly:

 UIImageView *imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; imageView.image = myImage; [self.view addSubview:imageView]; 
  • Enough to correct this answer already. if you have any idea how to do it differently write your answer. - Max Mikheyenko
  • Why use the borders of the screen and not the view ? - Gralex
  • @ Sk0prion next time ask right away, and do not vandalize other people's answers. I will start from afar: There is no context in the question, why does the questioner need it, and from my own experience (and I've been here for more than half a year), I know that in most cases I guess what the author really needs is impossible. Take for example this question. Maybe a person wants to show a modal view, maybe he writes his alertView and he needs to darken everything under him and so on. And as you can see, the answer would be different for each case, a продолжение ниже - Max Mikheyenko
  • for a modal window, you must use a modal VC, for an alert, it would be better to create a separate window on top of all content, and so on. They came to the answer to your question: without knowing the context of the question, in my opinion it would be best to answer the question exactly as it was asked - the person asked how to fill the весь экран picture, and received an answer using the size of the entire screen, not the controller. If it seems to you that it would be more correct to use the size of the parent controller view (and I do not say that I disagree with you on this) - write a comment or your answer. - Max Mikheyenko 1:53 pm
  • I do not want to mislead any of the newbies. There is a UIScreen in which information about the screen is stored (the size of one point, the size of the screen). Take from there info to set the frame is fundamentally wrong. In that case, it probably led to the correct result, only because the view has borders like that of the screen . We need a full-screen : we set the boundaries of the parent view ( bounds ), we throw on this view . - Gralex

If it is about how to bring the picture to the fore then:

 CGRect rect = self.view.bounds; UIImage* myImage = [UIImage imageNamed:@"bla-bla.png"]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect]; imageView.image = myImage; [self.view addSubview:imageView]; [self.view bringSubviewToFront:imageView]; 
  • Thank you. Your option also proved useful to me, but a colleague gave an answer earlier. - Andrew Kachalin
  • This option is more correct - Gralex

You can add a subview on top of all controllers, in this case it will be a UIImageView with your image as a subview of a UIWindow through standard addSubiew.

 UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage]; MyAppDelegate* myDelegate = (((MyAppDelegate*) [UIApplication sharedApplication].delegate)); [myDelegate.window addSubview: imageView]; 

    If you need right on top of everything, then it is better to do this:

    [[UIApplication sharedApplication].windows.firstObject addSubview:imageView]

    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky
    • I’m not sure whether it’s better =) playing at the window level can lead to sad consequences. If you can not do this, it is better to do it in another way. - Gralex