mLamaa mLamaa - 3 months ago 33
Objective-C Question

Subview displaying outside the bounds of the parent UIView

I have a UIView that contain another subview. The subview's frame is outside of the bounds of the super view. But the entire subview is visible in when I run the application.
Example:

++++++++++++++++++++++++++++
+ +
+ Super view +
+ +
+ +
+ --------------------------
+ - Subview + -
+ - + -
+ --------------------------
+ +
+ +
++++++++++++++++++++++++++++


Should be:

++++++++++++++++++++++++++++
+ +
+ Super view +
+ +
+ +
+ ---------------------+
+ - Subview +
+ - +
+ ---------------------+
+ +
+ +
++++++++++++++++++++++++++++


Any idea?

Answer

If you're setting up your views in code, set the clipsToBounds property of the superview to YES.

If you're setting up your views in a nib, turn on the “Clip Subviews” checkbox on the superview. It's off by default, as in this screenshot:

Clip Subviews checkbox