UIView hide children views when out of bounds

IphoneUiviewVisibility

Iphone Problem Overview


I have a view, lets say 100x100. And it has set of uiviews as subviews: let say 30x30

If a subview has top-left coordinate: (90,90) - I expect to see only part of this subview. But I still see entire area - even if it is out of parents bounds

The question is how to make uiview to show only those parts of subview, which are in original bounds?

thank you

Iphone Solutions


Solution 1 - Iphone

Set the parent view's clipsToBounds property to YES.

Programmatically: view.clipsToBounds=YES;

Through interface builder: Click the view->Attributes Inspector->Check Clip to Bounds

Solution 2 - Iphone

I think you want to enable "clip subviews" on the parent view.

Solution 3 - Iphone

The documentation says that the clipsToBounds property of UIView will clip the drawing to the bounds, or more precisely that the subview can't draw outside of the bounds of the superview.

for more read the SO post

https://stackoverflow.com/questions/820919/uiview-clipstobounds-property-does-it-improve-performance

Solution 4 - Iphone

Indeed, from the storyboard, tick the parent UIView's "Clip Subviews" checkbox. This is how it worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser349302View Question on Stackoverflow
Solution 1 - IphoneVladimirView Answer on Stackoverflow
Solution 2 - Iphonejd.View Answer on Stackoverflow
Solution 3 - IphoneJhaliya - Praveen SharmaView Answer on Stackoverflow
Solution 4 - IphoneMaria StoicaView Answer on Stackoverflow