每次单击 UI 按钮时,我都试图按照句子单词的顺序将句子的单词初始化为 UIlabels。
我还想识别不同标签中的句子何时接近屏幕末尾,然后将下一个单词放在句子单词下方的行中,就像在 Microsoft Word 中按 Enter 一样。
我已经尝试过这段代码,但它会将所有单词加载到同一个位置。
- (void)change:(id)sender
{
NSString *sentence = @"i am a boy with passion";
NSArray *array = [sentence componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@" "]];
CGFloat xVal = 11.0;
for (NSString *words in array) {
UILabel *labelText = [[UILabel alloc]initWithFrame:CGRectMake(xVal, 50, 300, 80)];
labelText.layer.borderColor = [UIColor blueColor].CGColor;
labelText.layer.borderWidth = 6.0;
labelText.backgroundColor = [UIColor clearColor];
labelText.textColor = [UIColor blackColor];
labelText.font = [UIFont boldSystemFontOfSize:20.0f];
labelText.text = words;
xVal=+200;
[self.view addSubview:labelText];
[labelText setUserInteractionEnabled:YES];
[labelText sizeToFit];