Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何实现标签_Ios_Iphone_Objective C_Tags - Fatal编程技术网

Ios 如何实现标签

Ios 如何实现标签,ios,iphone,objective-c,tags,Ios,Iphone,Objective C,Tags,我正在开发一个应用程序,我需要为每个讨论和每个评论显示标签,如下图所示。我从服务部得到了这样的标签 tags = ( Registration, Apps, PublicSpeaking, Marketing, Sales ); 我希望这些标签显示在给定图像的“标签”部分下 这就是我试图

我正在开发一个应用程序,我需要为每个讨论和每个评论显示标签,如下图所示。我从服务部得到了这样的标签

tags =             (
                Registration,
                Apps,
                PublicSpeaking,
                Marketing,
                Sales
            );
我希望这些标签显示在给定图像的“标签”部分下

这就是我试图实现的,任何类型的教程或链接都将非常有用

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];
for(int i=0;i<[self.menulistaray count];i++){
NSString*tag_string=[self.menulistaray objectAtIndex:i];
CGSize tagSize=[tag_字符串大小WithFont:[UIFont fontWithName:@“Roboto Light”大小:13.0]
约束状态:CGSizeMake(230,最大飞行高度)
lineBreakMode:UILineBreakModeTailTruncation];
UIImageView*标记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:否];
UILabel*tagLabel=[[UILabel alloc]init];
[tagLabel setFrame:CGRectMake(0,0,tagSize.width,25)];
[tagLabel setBackgroundColor:[UIColor clearColor]];
[tagLabel setText:tag_字符串];
[tagLabel setFont:[UIFont fontWithName:@“Roboto Light”大小:12.0];
[tagLabel setTextAlignment:NSTextAlignmentCenter];
[tag_bgimage addSubview:tagLabel];
[单元格添加子视图:标记\ bgimage];
}您可以使用控制器。看起来是这样的:


我建议UICollectionView实现标记,而不是使用添加框架。它的代码更少,开销更少,易于实现

按照此链接执行以下操作:

这就是它的样子。请注意它也是灵活的


希望这能帮助你

你能再解释一下吗。tag在这里做什么?你能更具体一点吗。。是否要显示3个以上的标记或其他内容?标记只是为了确定此讨论属于什么主题。像stackoverflow一样,我们需要设置提问的标签。标签可以是任意数字。也有三个以上。看,这是显示令牌文件,您可以将其扩展到您的代码中