ios - Show recipient as UIButton -


similar iphone mail, want display recipients uibutton. not able implement correctly.
creating recipients on single uilabel , assigning attributed text it.

nsmutablearray *arrrecipients = [nsmutablearray new];  if([message.recipients containsstring:@", "]) {     nsarray *arr = [message.recipients componentsseparatedbystring:@", "];      for(int = 0; < arr.count; i++)     {         [arrrecipients addobject:[arr objectatindex:i]];     } } else {     [arrrecipients addobject:message.recipients]; }  nsstring *recipientstring = @"";  for(int = 0; < arrrecipients.count; i++) {     if([recipientstring isequal:@""])         recipientstring = [arrrecipients objectatindex:i];     else         recipientstring = [recipientstring stringbyappendingstring:[nsstring stringwithformat:@" %@", [arrrecipients objectatindex:i]]];  }  nsmutableattributedstring *str = [[nsmutableattributedstring alloc]initwithstring:[nsstring stringwithformat:@"%@: %@", nslocalizedstring(@"to", nil), recipientstring]];  for(nsstring *value in arrrecipients) {     nsrange range = [recipientstring rangeofstring:value];     [str addattribute:nsbackgroundcolorattributename value:[uicolor colorwithred:205.0/255.0 green:205.0/255.0 blue:205.0/255.0 alpha:1.0] range:nsmakerange(range.location + 4, range.length)]; }  uilabel *recipients = [[uilabel alloc]initwithframe:cgrectmake(5, subject.frame.origin.y + subject.frame.size.height + 6, viewheader.frame.size.width - 5, 20)]; recipients.attributedtext = str; recipients.numberoflines = 0; recipients.font = [uifont systemfontofsize:14]; [viewheader addsubview:recipients]; [recipients sizetofit];  [viewheader sizetofit];   

results :

enter image description here

not quite one.

how can improve ?

like in mail or in other apps can have functionality of tags can differentiate between list of items. below links may out: https://www.cocoacontrols.com/search?q=tags https://www.cocoacontrols.com/controls/aktagsinputview


Comments