Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextview clipping with three dots?

I have a UITextView showing some dynamic content that can vary in size. The textview has no scrolling allowed and its size is independent from the content. Given its auto-layout constraints, the text view has a different horizontal size on iphone5 and iPhone6plus for example.

What I would like is my text to be clipped when necessary with 3 dots at the end like that “…”. (there is a "More" UIButton launching safari below the UITextView)

I’m not sure if there is a UITextView property or if i should consider some code that checks how many characters the textview can display in the current circumstances and modify my string to be shown accordingly (cutting and appending @“…”).

Thank you.

like image 615
MikaelW Avatar asked Sep 23 '15 09:09

MikaelW


1 Answers

Try setting the UITextView line break mode. It works just like UILabel and should use "..." at the end.

self.textView.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;

See https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSTextContainer_Class_TextKit/index.html#//apple_ref/occ/instp/NSTextContainer/lineBreakMode

like image 159
Rory McKinnel Avatar answered Sep 30 '22 20:09

Rory McKinnel