3

I have a UIViewController object in a .xib file. I add a UIImageView to it, and then try to add a button as a subview of the UIImageView. It instead replaces the UIImageView. It works fine if both are subviews of a UIView. What gives? I thought this would work since UIImageView is a subclass of UIView?

Marty
  • 5,926
  • 9
  • 53
  • 91
  • This used to be an Interface Builder bug, however I don't know if it's been fixed yet. – BoltClock Feb 03 '11 at 23:39
  • In my opinion this isn't a bug, programatically a UIImageView is a subclass of UIView, and so can have subviews, but it's not rocket science to recognize that the image view object is somewhat simplistic in it's goal - display an image. I believe it's intended to not add subviews via IB, because it's obvious you shouldn't be doing that. Instead use a UIView and set it's backgroundImage property, or if more complex have a couple of image view's as subview of a view. – Daniel Feb 25 '13 at 12:21

2 Answers2

3

Only Apple knows.

However, look at here for a workaround:

Apple Interface Builder: adding subview to UIImageView

Community
  • 1
  • 1
user4951
  • 32,206
  • 53
  • 172
  • 282
0

A UIImageView is it's own object and a UIButton is its own object. A UIImageView is an outlet placeholder for an image. If you're trying to add a background image to a button you can use the background image property or if you'd like the background to span beyond the bounds of the button you can drop a UIView onto IB and style that using code or subclassing UIImageView.

pablasso
  • 2,479
  • 2
  • 26
  • 32
TALLBOY
  • 1,079
  • 1
  • 10
  • 13