How to make portion of a subview invisible when protruding from a superview?

StackOverflow https://stackoverflow.com/questions/23665035

  •  22-07-2023
  •  | 
  •  

Frage

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.

War es hilfreich?

Lösung

Set the superview's clipsToBounds property to YES.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top