ios - Counting the number of lines in a UITextView, lines wrapped by frame size -


i wanted know when text wrapped frame of text view there delimiter can identify whether text wrapped or not.

for instance if text view has width of 50 px , text exceeding that, wraps text next line.

i wanted count number of lines in text view. "\n" , "\r" not helping me.

my code is:

nscharacterset *acharacterset = [nscharacterset charactersetwithcharactersinstring:@"\n\r"];     nsarray *myarray = [textviewtext componentsseparatedbycharactersinset:acharacterset];     nslog(@"%d",[myarray count]); 

this variation takes account how wrap lines , max size of uitextview, , may output more precise height. example, if text doesn't fit truncate visible size, , if wrap whole words (which default) may result in more lines if otherwise.

uifont *font = [uifont boldsystemfontofsize:11.0]; cgsize size = [string sizewithfont:font                        constrainedtosize:myuitextview.frame.size                        linebreakmode:uilinebreakmodewordwrap]; // default mode float numberoflines = size.height / font.lineheight; 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -