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?
Asked
Active
Viewed 5,794 times
3
-
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 Answers
3
Only Apple knows.
However, look at here for a workaround:
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
.