Reputation: 1544
I am making an app in which there are multiple labels which need to show up one after the other in a chain. Now, it would be really difficult if I had to create several labels with separate text on each one of them. So is there any way in which I can create one label, display it on the screen, then change the text of the same label by duplicating it, and display that just below the previous one?
Upvotes: 0
Views: 1867
Reputation: 10172
Suggestion from luk2302 (in comments) is best way to achieve what you wanna do. But if you really-really wanna create multiple label
bellow code will help.
You can use for
loop to create several loop (as you either copy or create new it will take same amount of memory):
for (var i = 0; i < 10; i++){
print("%d",i)
var label = UILabel(frame: CGRectMake(0, 21*i+5, 200,21))
label.center = CGPointMake(160, 284)
label.textAlignment = NSTextAlignment.Center
label.text = "I'am a test label"
self.view.addSubview(label)
}
Upvotes: 1