ios - Two Lines in UITableViewCell's textLabel with new line being determined ONLY by newline character in text -


i want format cell's textlabel display text on 2 lines, line break character determining second line begin. problem that, since not control text in first line, text on first line spills on second line , second line text not display @ all. specifying uilinebreakmodewordwrap breaks word in 2 wrap it, makes no sense (i use first line names). need 2 lines , 2 lines label, there room in particular cell. using detailtextlabel else. not want create custom cell this. possible asking?

here's do:

you take long string, split 2 componentsseparatedbystring, take each piece, use iterative sizewithfont:constrainedtosize:linebreakmode calculate longest string fits default textlabel width, take 2 newly crafted strings , append them '\n' character. use textlabel text.

that should achieve you're trying do. highly recommend you favor , go custom. number of reasons:

  1. yes, custom cells typically take longer create. but, i'd argue in particular case, faster go custom implement above. implementation above doesn't account ellipses @ ends of truncated strings. can throw mix, that's gonna add more time , complexity. custom cells , individual labels, becomes gimme.
  2. custom allows give 2 lines of text own fonts/sizes. using ib, basic styling on these fields becomes breeze. , that's pretty slick bonus. users especially. mention first line of text names - why not make bold better distinguish second line of text?
  3. if plan on creating , releasing ios apps in future, you're gonna making lot of custom cells. why not use 1 practice?

if need guidance on creating custom cells, this pretty thorough tutorial.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -