ios - Put 2 NSAttributedStrings in one Label -


is possible put 2 nsattributedstrings in 1 label?

for example:

nsstring *a =  [car valueforkey:@"name"]; nsstring *b =  [car valueforkey:@"version"];  nsattributedstring *title;     title = [[nsattributedstring alloc] initwithstring:a attributes:@{ nsfontattributename : [uifont fontwithname:@"noteworthy-bold" size:36], nsunderlinestyleattributename : @1 , nsstrokecolorattributename : [uicolor blackcolor]}]; //1      nsattributedstring *title2;     title2 = [[nsattributedstring alloc] initwithstring:b attributes:@{ nsfontattributename : [uifont fontwithname:@"noteworthy-bold" size:36], nsunderlinestyleattributename : @0 , nsstrokecolorattributename : [uicolor blackcolor]}]; //2      cell.textlabel.attributedtext = //what should write here? 

you can use -appendattributedstring:(nsstring *) method append 1 attributed string other. since can make both of attributed strings mutable, can include separators (semicolons, commas) differentiate between 2 different strings in 1 label.

here sample code:

nsmutableattributedstring *string1 = [[nsmutableattributedstring alloc] initwithstring:@"hello"];         nsmutableattributedstring *string2 = [[nsmutableattributedstring alloc] initwithstring:@"hello 2"]; nsmutableattributedstring *semistr = [[nsmutableattributedstring alloc] initwithstring:@" ; "]; [string1 appendattributedstring:semistr]; //separate string 1 , 2 semi-colon         [string1 appendattributedstring:string2];  textlabel.text = string1; //which string2 appended 

obviously, in attributed strings, have attributes (like stated in question). can trust apple's documentation on nsmutableattributedstring class find suitable methods use next time.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -