Question

I have a UIView subview within a superview whose frame may extend outside the frame of the superview:

e.g. superview.frame = CGRectMake(0,0,100,100); subview.frame = CGRectMake(50,50,60,60);

i.e The subview will 'protrude' from the superview by 10 pixels in the bottom right corner.

How can I make it so only the portion of the subview that is within the superview frame is visible, and the protruding part invisible?

Context: The subview is actually a UILabel, which cannot be resized. If it protrudes, I want to display half the text only.

Was it helpful?

Solution

Set the superview's clipsToBounds property to YES.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top