我使用 for 循环创建了 5 个 UILabels
,我已将每个项目标签设置为循环计数。我在 viewdidload
方法中执行此操作,但稍后我尝试使用 .tag
UILabels
之一
这是我创建 UILabel 的方法
for (int i = 0; i < 5; i++) {
finishingCopyWidthLabel = [[UILabel alloc] initWithFrame:CGRectMake((i * quickSelectionBarSectionWidth)-180, 2.0, 100.0, 20.0)];
finishingCopyWidthLabel.backgroundColor = [UIColor clearColor];
finishingCopyWidthLabel.textAlignment = NSTextAlignmentCenter;
finishingCopyWidthLabel.text = @"";
finishingCopyWidthLabel.tag = i;
[quickSelectionBar addSubview:finishingCopyWidthLabel];
}
然后这就是我尝试将文本分配给 UILable
的方式,但是它不起作用,任何帮助使分配工作的帮助都很棒。
UILabel *fCopyWidthLabel = (UILabel *)[finishingCopyWidthLabel viewWithTag:1];
fCopyWidthLabel.text = [prefsDictionary objectForKey:@"QuickWidthOne"];
最佳答案
根据你的问题更新,而不是这个 UILabel *fCopyWidthLabel = (UILabel *)[finishingCopyWidthLabel viewWithTag:1];
试试这个
UILabel *fCopyWidthLabel = (UILabel *)[quickSelectionBar viewWithTag:1];
关于ios - 使用标记符号 objective-c 将文本分配给 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21549286/