开发者

Content IN UILABEL is Overlapping

HI, I am using the following code for displaying data dynamically on a label.ITs working fine.But sometimes the content is overlapping with the subhead title and description.Please help me in this.I am not able to trace out this.THANKS IN ADVANCE

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 
                                   开发者_如何学Go       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];

        }

    }


I think both subheadTitle and subheadlabel will overlaps because of their frame. Can you check the values of expectedLabelSize in both cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜