Reputation: 2512
I'm developing an application where i need to show the tags for every discussion and every comment as shown in image below. I'm getting the tags from service something like this.
tags = (
Registration,
Apps,
PublicSpeaking,
Marketing,
Sales
);
I want these tags to display under "tag" part of the given image.
this is how i was trying to implement, any kind of tutorial or link will be very helpful.
for (int i=0; i< [self.menuListArray count]; i++) {
NSString *tag_string = [self.menuListArray objectAtIndex:i];
CGSize tagSize = [tag_string sizeWithFont:[UIFont fontWithName:@"Roboto-Light" size:13.0]
constrainedToSize:CGSizeMake(230, FLT_MAX)
lineBreakMode:UILineBreakModeTailTruncation];
UIImageView *tag_bgimage = [[UIImageView alloc]init];
[tag_bgimage setFrame:CGRectMake(i*tagSize.width+5, stringSize.height+5, tagSize.width+4, 25)];
[tag_bgimage setBackgroundColor:[UIColor grayColor]];
[tag_bgimage setUserInteractionEnabled:NO];
UILabel *tagLabel = [[UILabel alloc]init];
[tagLabel setFrame:CGRectMake(0, 0, tagSize.width, 25)];
[tagLabel setBackgroundColor:[UIColor clearColor]];
[tagLabel setText:tag_string];
[tagLabel setFont:[UIFont fontWithName:@"Roboto-Light" size:12.0]];
[tagLabel setTextAlignment:NSTextAlignmentCenter];
[tag_bgimage addSubview:tagLabel];
[cell addSubview:tag_bgimage];
}
Upvotes: 0
Views: 497
Reputation: 91
Instead of using addition framework, I recommend UICollectionView to implement Tags. It's less code, less overhead and easy to implement.
Follow this link for implementing:
https://codentrick.com/create-a-tag-flow-layout-with-uicollectionview/
This is how it looks like. Please note it is flexible too.
Hope this will help you
Upvotes: 0