如何在iPhone中水平打印UILabel上的多个值

时间:2012-03-29 06:39:39

标签: iphone objective-c

嗨朋友我现在如果我使用这个代码它将在标签上打印多个值但在新行我不想要

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{



    CGSize labelSize = CGSizeMake(200.0, 20.0);
    if ([displayTag length] > 0)
        labelSize = [displayTag sizeWithFont: [UIFont boldSystemFontOfSize: 17.0] constrainedToSize: CGSizeMake(labelSize.width, 1000) lineBreakMode: UILineBreakModeWordWrap];
    return 24.0 + labelSize.height;
    }
    return 40.0;
}

此代码将打印垂直线但我想在水平标签上打印我的值如何在特定单元格上水平标签上打印多个值

因为我是创造但是不起作用 哪里我错了 这个代码在我的自定义单元格中

TagsLable= [[UILabel alloc]initWithFrame:CGRectMake(360, 15, 150, 21)];
            TagsLable.font = [UIFont fontWithName:@"Verdana" size:16.0f];
            TagsLable.textAlignment=UITextAlignmentRight;
            TagsLable.backgroundColor=[UIColor clearColor];



CGSize fontSize = [tagList sizeWithFont: [UIFont boldSystemFontOfSize: 17.0]];
        double finalWidth = fontSize.width *  UIBaselineAdjustmentAlignBaselines;
        //double finalWidth = fontSize.width + self.numberOfLines;
        double finalHeight = self.frame.size.height;    //expected height of label
        CGSize theStringSize = [tagList sizeWithFont: [UIFont boldSystemFontOfSize: 17.0] constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode: UILineBreakModeWordWrap];
        int newLinesToPad = (finalWidth  - theStringSize.width) / fontSize.width;
        for(int i=0; i<newLinesToPad; i++)
        {
            //tagList = [tagList stringByAppendingString:@","];
        tagList=[tagList stringByAppendingFormat:@"%@, ",tag.TagName];
        }

1 个答案:

答案 0 :(得分:0)

什么是 tag.TagName

试试这个

tagList=[tagList stringByAppendingFormat:@"%@, ",tag.TagName];

NSString *tagList = [tagList stringByAppendingPathComponent:TagName.tag];