UIView hide children views when out of bounds

2019-03-09 05:53发布

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

4条回答
Bombasti
2楼-- · 2019-03-09 06:29

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?

查看更多
不美不萌又怎样
3楼-- · 2019-03-09 06:33

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

查看更多
孤傲高冷的网名
4楼-- · 2019-03-09 06:34

Set view's clipsToBounds property to YES.

Programmatically: view.clipsToBounds=YES;

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

查看更多
甜甜的少女心
5楼-- · 2019-03-09 06:45

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

查看更多
登录 后发表回答