0

What UI element should I use for a background image in an iOS application? The image is quite small (98*51) and I'll need to put a small label and two buttons on top of it. I tried both using a label (but can't find where to change the dimension and I wasn't able to change it to the correct one using only the mouse) and an UIImageView. Any suggestions?

3 Answers3

0

If you are using interface builder, there should be no problem using a UIImageView with the appropriate dimensions, then placing the label and buttons on top of it. You can access the size of any of the elements from the size inspector in the right panel (the icon looks like a little ruler).

JAB
  • 3,165
  • 16
  • 29
  • Thanks for pointing to the size inspector. One more question though: for some reason my UIImageView element stays on top of everything else. So when I put a label on top the text isn't visible because it's underneath the image. Any idea how to change this? –  Aug 19 '12 at 17:39
  • you need to rearrange the order of the elements on the left hand panel. Put the image view above the label and buttons – JAB Aug 19 '12 at 17:43
  • which one do you mean with the left hand panel? –  Aug 19 '12 at 17:46
  • the one that shows the collapsable list of your views and all the objects in them. If the panel is closed, just click the little arrow in the bottom left. – JAB Aug 19 '12 at 17:51
  • Found it! Thanks, I had never noticed the arrow before. –  Aug 19 '12 at 17:53
0

Both ways that you tried should work. Your first approach sounds simpler to implement, but your second approach is more flexible.

Using your first approach, you can place the image behind the label using this the technique described in this answer, setting the dimensions of the entire label by setting its label.frame = CGMakeRect(x, y, 98, 51).

The UIImageView route should be rather straightforward, too. Just remember to set label's background to transparent, as described in this answer.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0

I'm not sure I fully understand your question but if you want a tiled background image the simple way is to use this:

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imagedNamed:@"myImage.png"]]];
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281