ios - Align label from left and right that have "\n" -


i have 1 label text this

label.text = "a    34\nb    11\nc    4\nd    3" 

it this

a      34 b     11 c       5 d    3 

is there way align label left , right like:

a      34 b      11 c       5 d       3 

`you make row class (custom uiview) , have each "column" element (separate uilabel) set data used populate it. have table class use longest string , adjust positioning of each column. approach give lot of control, work.

or use nsattributedstring tab stops.

let mytext = "a\t34\nb\t11\nc\t5\nd\t3" let paragraphstyle = nsmutableparagraphstyle() paragraphstyle.tabstops = [nstexttab(textalignment: nstextalignment.left, location: 150, options: [:])] paragraphstyle.headindent = 150 label.attributedtext = nsattributedstring(string: text, attributes:[nsparagraphstyleattributename: paragraphstyle]) 

you can calculate longest string width in loop determine headindent should be. however, wouldn't allow right column right-aligned in example. like:

a        34 b        11 c        5 d        3 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -