S B
S B

Reputation: 8384

Truncating NSString to fit a particular width

I've got a variable-width-font NSString that has to fit inside a fixed size UIView. Currently, the string gets truncated and rendered.

I want to obtain the visible substring so I can append an elipsis (…) to it.

Upvotes: 1

Views: 477

Answers (1)

Tim
Tim

Reputation: 14446

If you're using a UILabel, you can set the lineBreakMode to one of

UILineBreakModeHeadTruncation
UILineBreakModeTailTruncation
UILineBreakModeMiddleTruncation

The different positions refer to where the ... goes. You want UILineBreakModeTailTruncation.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UILabel_Class/Reference/UILabel.html#//apple_ref/occ/instp/UILabel/lineBreakMode

Upvotes: 1

Related Questions