内容IN UILABEL重叠

嗨, 我正在使用下面的代码在label.ITs上动态显示数据正常工作。但有时内容与子标题和description.Please帮助我重叠。我是不能追踪出this.THANKS IN ADVANCE内容IN UILABEL重叠

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];

}

}

回答:

我认为无论subheadTitlesubheadlabel会重复,因为他们frame的。你能否在两种情况下检查expectedLabelSize的值。

以上是 内容IN UILABEL重叠 的全部内容, 来源链接: utcz.com/qa/262761.html

回到顶部