我有三个标签,并且基于文本正在增加。虽然我contentsize
从超级视图中删除并再次创建这个时间框架高度正在增加底部控制。UIScrollview
Scrollview
更新前:
再次创建后:
如果您不清楚要提问,请告诉我。
-(void)setDataDynamicallyonScroll
{
if (self.infoScroll) {
[self.infoScroll removeFromSuperview];
self.infoScroll = nil;
}
self.infoScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(10.0f, 55.0f, 300, 450)];
self.infoScroll.autoresizingMask = UIViewAutoresizingFlexibleHeight;
UILabel *mainTitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
UILabel *subTitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
UILabel *detailsTitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
if ([[self.dataDic valueForKey:@"subData"] valueForKey:@"FirstText"]!=nil) {
NSString *labelText = [[self.dataDic valueForKey:@"subData"] valueForKey:@"FirstText"];
[mainTitleLabel setText:labelText];
// Tell the label to use an unlimited number of lines
[mainTitleLabel setNumberOfLines:0];
[mainTitleLabel setBackgroundColor:[UIColor clearColor]];
[mainTitleLabel setFont:[UIFont boldSystemFontOfSize:12]];
mainTitleLabel.textColor = [UIColor colorWithRed:13.0/255.0 green:52.0/255.0 blue:112.0/255.0 alpha:1.0];
//[infoLabel sizeToFit];
CGSize infoLabelSize = [mainTitleLabel.text sizeWithFont:mainTitleLabel.font
constrainedToSize:CGSizeMake(self.infoScroll.frame.size.width, 9000)
lineBreakMode:NSLineBreakByWordWrapping];
mainTitleLabel.frame = CGRectMake(0, 0, infoLabelSize.width, infoLabelSize.height);
self.infoScroll.contentSize = infoLabelSize;
NSLog(@"%f,%f,%f,%f ",mainTitleLabel.frame.origin.x,mainTitleLabel.frame.origin.y,mainTitleLabel.frame.size.width,mainTitleLabel.frame.size.height);
NSLog(@"for First %f",self.infoScroll.contentSize.height);
[self.infoScroll addSubview:mainTitleLabel];
}
if ([[self.dataDic valueForKey:@"subData"] valueForKey:@"MiddleText"]!=nil) {
AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
switch ([delegate langType]) {
case 0:
[subTitleLabel setText:[[[self.dataDic valueForKey:@"subData"] valueForKey:@"MiddleText"] valueForKey:@"English"]];
break;
case 1:
[subTitleLabel setText:[@"\u200F" stringByAppendingString:[[[self.dataDic valueForKey:@"subData"] valueForKey:@"MiddleText"] valueForKey:@"Hebrew"]]];
break;
case 2:
[subTitleLabel setText:[[[self.dataDic valueForKey:@"subData"] valueForKey:@"MiddleText"] valueForKey:@"Trans"]];
break;
default:
break;
}
// Tell the label to use an unlimited number of lines
[subTitleLabel setNumberOfLines:0];
[subTitleLabel setBackgroundColor:[UIColor clearColor]];
[subTitleLabel setFont:[UIFont boldSystemFontOfSize:13]];
[subTitleLabel setTextAlignment:NSTextAlignmentRight];
subTitleLabel.textColor = [UIColor colorWithRed:155.0/255.0 green:0/255.0 blue:16.0/255.0 alpha:1.0];
//[infoLabel sizeToFit];
CGSize infoLabelSize = [subTitleLabel.text sizeWithFont:subTitleLabel.font
constrainedToSize:CGSizeMake(self.infoScroll.frame.size.width, 9000)
lineBreakMode:NSLineBreakByWordWrapping];
subTitleLabel.frame = CGRectMake(0, self.infoScroll.contentSize.height+20, infoLabelSize.width, infoLabelSize.height);
CGSize updatedScrollViewContentSize = CGSizeMake(300,self.infoScroll.contentSize.height+infoLabelSize.height+20 );
self.infoScroll.contentSize = updatedScrollViewContentSize;
[self.infoScroll addSubview:subTitleLabel];
}
if ([[self.dataDic valueForKey:@"subData"] valueForKey:@"LastText"]!=nil) {
[detailsTitleLabel setText:[[self.dataDic valueForKey:@"subData"] valueForKey:@"LastText"]];
// Tell the label to use an unlimited number of lines
[detailsTitleLabel setNumberOfLines:0];
[detailsTitleLabel setBackgroundColor:[UIColor clearColor]];
[detailsTitleLabel setFont:[UIFont systemFontOfSize:13]];
[detailsTitleLabel setTextAlignment:NSTextAlignmentLeft];
detailsTitleLabel.textColor = [UIColor blackColor];
[detailsTitleLabel sizeToFit];
CGSize infoLabelSize = [detailsTitleLabel.text sizeWithFont:detailsTitleLabel.font
constrainedToSize:CGSizeMake(self.infoScroll.frame.size.width, 9000)
lineBreakMode:NSLineBreakByWordWrapping];
UIImageView *bgView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"detailsTextbg.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 12, 12)]];
bgView.frame = CGRectMake(0,self.infoScroll.contentSize.height+20, infoLabelSize.width, infoLabelSize.height+20);
detailsTitleLabel.frame = CGRectMake(5,10, infoLabelSize.width, infoLabelSize.height);
CGSize updatedScrollViewContentSize = CGSizeMake(300,self.infoScroll.contentSize.height+detailsTitleLabel.frame.size.height+50);
self.infoScroll.contentSize = updatedScrollViewContentSize;
[bgView addSubview:detailsTitleLabel];
[self.infoScroll addSubview:bgView];
}
[self.view addSubview:self.infoScroll];
}