我必须使用自定义标签制作一个 pdf 生成器,所以在我的故事板中,我有一个 UIScrollView,里面有一个 UIView,如果我的 UIView 已满,我想添加另一个 UIView 并用其他尚未添加的标签填充它。如何使用另一个 UIView 在我的 UIScrollView 中添加另一个页面?我必须以编程方式进行,或者情节提要中有一个选项可以做到这一点?
我试过这个(我不知道它是否有效,我不想编译它,因为我觉得它真的很难看):
CGFloat placement = titleLabel.frame.size.height + kMarginLabel;
for(int i = 0; i < [contract.nameContract count]; i++)
{
if(placement > _contractPageView.frame.size.height)
{
CGFloat secondPlacement = 0;
_scrollView.contentSize = CGSizeMake(_contractPageView.frame.size.width * 2, _contractPageView.frame.size.height);
UIView *secondPage = [[UIView alloc] initWithFrame:_contractPageView.frame];
articleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0 + kMarginLabel, secondPlacement, kTitleHeight, kTitleWidth)];
articleLabel.text = [NSString stringWithFormat:@"Article %i - %@",i, [contract.nameContract objectAtIndex:i]];
[secondPage addSubview:articleLabel];
secondPlacement += articleLabel.frame.size.height;
clauseLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, secondPlacement + kMarginLabel, _contractPageView.frame.size.width, kSizeOfClause)];
clauseLabel.text = [contract.textContract objectAtIndex:i];
secondPlacement += clauseLabel.frame.size.height;
[secondPage addSubview:clauseLabel];
[_scrollView addSubview:secondPage];
if(secondPlacement > secondPage.frame.size.height)
{
CGFloat thirdPlacement = 0;
_scrollView.contentSize = CGSizeMake(_contractPageView.frame.size.width * 3, _contractPageView.frame.size.height);
UIView *thirdPage = [[UIView alloc] initWithFrame:_contractPageView.frame];
articleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0 + kMarginLabel, thirdPlacement, kTitleHeight, kTitleWidth)];
articleLabel.text = [NSString stringWithFormat:@"Article %i - %@",i, [contract.nameContract objectAtIndex:i]];
[thirdPage addSubview:articleLabel];
thirdPlacement += articleLabel.frame.size.height;
clauseLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, thirdPlacement + kMarginLabel, _contractPageView.frame.size.width, kSizeOfClause)];
clauseLabel.text = [contract.textContract objectAtIndex:i];
thirdPlacement += clauseLabel.frame.size.height;
[thirdPage addSubview:clauseLabel];
[_scrollView addSubview:thirdPage];
}
} else {
articleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, placement, kTitleHeight, kTitleWidth)];
articleLabel.text = [NSString stringWithFormat:@"Article %i - %@",i, [contract.nameContract objectAtIndex:i]];
[_contractPageView addSubview:articleLabel];
placement += articleLabel.frame.size.height;
clauseLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, placement + kMarginLabel, _contractPageView.frame.size.width, kSizeOfClause)];
clauseLabel.text = [contract.textContract objectAtIndex:i];
placement += clauseLabel.frame.size.height;
[_contractPageView addSubview:clauseLabel];
}
}
我不知道这是否是唯一的方法,想象一下如果我的数组中有很多很多很多对象,我必须创建越来越多的页面:/我不知道该怎么做:(
谢谢你的帮助。