ios - Change font of separate strings detailTextLabel -
how can change font of 1 string in detailtextlabel of uitableviewcell?
nsstring *detailstr = [nsstring stringwithformat:@"%@ %@",post.score,post.domain]; cell.detailtextlabel.text = detailstr; i want post.score string 1 color , post.domain string another.
answer : nsattributedstring.
try :
int count1 = [post.score length]; int count2 = [post.domain length]; nsmutableattributedstring *textlabelstr = [[nsmutableattributedstring alloc] initwithstring:@"%@ %@",post.score,post.domain]; [textlabelstr setattributes:@{nsforegroundcolorattributename : [uicolor redcolor], nsfontattributename : [uifont systemfontofsize:17]} range:nsmakerange(0, count1)]; [textlabelstr setattributes:@{nsforegroundcolorattributename : [uicolor bluecolor], nsfontattributename : [uifont systemfontofsize:17]} range:nsmakerange(count1 + 1, count2)]; cell.detailtextlabel.attributedtext = textlabelstr; note : not tested, write code you.
Comments
Post a Comment