Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView hide children views when out of bounds

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

like image 636
user349302 Avatar asked Mar 24 '11 17:03

user349302


4 Answers

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

like image 120
Vladimir Avatar answered Oct 16 '22 17:10

Vladimir


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

like image 33
jd. Avatar answered Oct 16 '22 18:10

jd.


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

UIView clipsToBounds property: Does it improve performance?

like image 41
Jhaliya - Praveen Sharma Avatar answered Oct 16 '22 17:10

Jhaliya - Praveen Sharma


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

like image 31
Maria Stoica Avatar answered Oct 16 '22 18:10

Maria Stoica