UILABEL中的内容重叠

时间:2011-03-11 10:45:59

标签: iphone uilabel

HI, 我正在使用以下代码在标签上动态显示数据。工作正常。但有时内容与小标题标题和说明重叠。请帮助我。我无法追溯到这一点。提前预测< / p>

for (int i=0; i<[article.subheadArray count]; i++) {

        //subhead Title
        subheadTitle = [[UILabel alloc] initWithFrame:CGRectMake(xoffset, yoffset+total, 320-xoffset, 300+lblheight)];
        subheadTitle.backgroundColor=[UIColor clearColor];
        //subheadTitle.textColor=[UIColor blueColor];
        [subheadTitle setFont: [UIFont fontWithName:@"Arial-BoldMT" size:17]];
        subheadTitle.textColor = [UIColor colorWithRed:45.0/255.0 green:99.0/255.0 blue:03.0/255.0 alpha:1];
        subHead = [article.subheadArray objectAtIndex:i];


        expectedLabelSize = [subHead.Title sizeWithFont:subheadTitle.font 
                                      constrainedToSize:maximumLabelSize 
                                          lineBreakMode:subheadTitle.lineBreakMode];
        newFrame = subheadTitle.frame;
        newFrame.size.height=expectedLabelSize.height;
        subheadTitle.frame=newFrame;    
        total+=expectedLabelSize.height+yoffset;
        NSLog(@"%@  %d",subHead.Title,total);
        subheadTitle.numberOfLines=0;
        subheadTitle.text=subHead.Title;

        [scrollView addSubview:subheadTitle];

        //subhead Description
        subheadlabel = [[UILabel alloc] initWithFrame:CGRectMake(xoffset, yoffset+total, 320-xoffset, 300+lblheight)];
        subheadlabel.backgroundColor=[UIColor clearColor];
        subHead = [article.subheadArray objectAtIndex:i];
        //subheadlabel.font = [UIFont italicSystemFontOfSize:fontsize];
        [subheadlabel setFont: [UIFont fontWithName:@"ArialMT" size:fontsize]];
        expectedLabelSize=[subHead.Description sizeWithFont:subheadlabel.font 
                                            constrainedToSize:maximumLabelSize 
                                                lineBreakMode:subheadlabel.lineBreakMode];
        newFrame = subheadlabel.frame;
        newFrame.size.height=expectedLabelSize.height;

        subheadlabel.frame=newFrame;    
        total+=expectedLabelSize.height+yoffset;
        subheadlabel.text = subHead.Description;
        NSLog(@"subhead desc: %d  %d",total,subheadlabel.numberOfLines);

        subheadlabel.numberOfLines =0;
        [subheadlabel sizeToFit];
        [scrollView addSubview:subheadlabel];       

        //Adding subhead label to subheadlabelarr
        [subheadlabelarr addObject:subheadTitle];

        //subhead Image
        for (int j=0; j<[subHead.imageArray count]; j++) {
            Image* image = [subHead.imageArray objectAtIndex:j];
            UIImage* uiImage = [XMLParsing getImagewithName:image.Name];

            CGSize imageSize = uiImage.size;
            if(imageSize.width>=300){
                width = 300;
            }
            else {
                width = imageSize.width;
            }

            if(imageSize.height>=200){
                height = 200;
            }else {
                height = imageSize.height;
            }


            imageView = [[UIImageView alloc] initWithFrame:CGRectMake((320-width)/2,yoffset+total,width,height)];
            //imageView = [[UIImageView alloc] initWithFrame:CGRectMake(200, yoffset+total, width, height)];
            imageView.clipsToBounds = YES;

            total+=imageView.frame.size.height+yoffset;
            //************cell.myImageView.image=[XMLParser getImagewithName:@"og_logo.png"];
            imageView.image = [XMLParsing getImagewithName:image.Name];
            [scrollView addSubview:imageView];

        }

    }

1 个答案:

答案 0 :(得分:0)

我认为subheadTitlesubheadlabelframe而重叠。在这两种情况下,您都可以检查expectedLabelSize的值。