我正在开发一个应用程序,其中我在函数中动态添加了 5 个标签。当我记忆起相同的函数时,尽管在每次创建时都释放了标签,但标签会覆盖之前创建的标签。
for(int i = 1; i < [array count]; i++)
{
CGRect lblframe = CGRectMake(count, ycord, width, height);
UILabel *label = [[UILabel alloc] initWithFrame:lblframe];
label.backgroundColor = [UIColor blackColor];
label.font = [UIFont systemFontOfSize:17];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor colorWithRed:(188/255.f) green:(149/255.f) blue:(88/255.f) alpha:1.0];;
label.text = [arr objectAtIndex:i];
count = count + xcord;
[subcatScroll addSubview:label];
[label release];
}
最佳答案
在for循环之前写下下面的代码来得到你的要求:
for (id object in [subcatScroll subviews]) {
[object removeFromSuperview];
}
关于iphone - 动态创建的标签被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7454615/