Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

I wanna have a new label with custom value every time the user hits the button

Hi I wanna have a new label with custom value every time the user hits the button so for example: I have a (text box) when the user hits the button (add) there will be a new label under the (text box) with the value that the user entered ,,

I was working on a solution but I seemed to have some problems , my solution was to have a big label and every time the user hits the button I'll get to a new line then write the new value but I had some troubles with that ! so can any one please give me a way to do that ?!

here is how I tested my idea (label called label and the text called text)the names are different from here but it has the same idea label = "\n (text)"

1 Answer

You'll probably have to make a scrollview, increase the content size's height and keep adding labels there.

I had this idea before but my problem is how to keep adding the labels -> I'm a beginner

Something like this(I don't have that much swift experience,so I'll go with objC):

//Calculate the upper right coordinate before hand

UIlabel *label=[[UIlabel alloc]initWithFrame:CGRectMake(newCoord.x,newCoord.y,width,height];
[scrollView addSubview:label];