0

So I am wanting to create a Scrollview with a list of labels. I am having a super hard time with the constraints and what not. It is obviously nothing like adding labels to a simple UIView.

What i need is one label in the top left corner, about 40% width from parent view with a top and left border of 10. Then i need a second label right next to it also with a 40% width and a top and right border of 10. After doing this i will continue creating labels under each other in the same sequence. All with borders of 10.

(P.S. I know labels have a set height value but i have been giving them values of 0.05% height of parent view just for organizing reasons.)

Now, normally when adding to a normal view i would match the parent width and height then go to the identity inspector and under the sizes-equalwidthsconstraint-multiplier set it to 0.4 and height etc. Then I would go to the pin and add the constraints top: 10 and left: 10. By that time i would be golden with the first label! However it doesnt work that way with scrollviews. I keep getting red lines every where and a caution alert saying "Scrollable content size is ambiguous for "Scroll View"".

(P.S. I have however been able to successfully create the first label, with red lines though, but when creating the second label i can never get it to line up right.)

If you dont know how to do it through storyboard and should do it programmatically then how would i do that? Swift please, always.

for example:

make: Chevrolet model: Silverado year: 2016 color: Pearl White

so on and so forth....

its basically a list of non editable text..

i was wanting to go for that look.

Please help, thank you!

AdrianGutierrez
  • 619
  • 1
  • 5
  • 11
  • Instead of adding labels to a scrollview, you should take advantage of `UICollectionView`. This should give you the behavior you want, and it manages the scrolling for you. – Nick Aug 11 '16 at 01:46
  • as @Nick said the easiest way is to use a `collection view`, or else you should have knowledge of `auto layouts`. – Chanaka Anuradh Caldera Aug 11 '16 at 03:51

1 Answers1

0

Use UITableView's. Apple has designed UITableView for these kinds of problem statements.

Here is a good place to start. http://code.tutsplus.com/tutorials/ios-from-scratch-with-swift-table-view-basics--cms-25160

And for your case, you need to use Custom UITableViewCell for your specific problem

Harsh
  • 2,702
  • 1
  • 11
  • 27
  • Thank you for your response. :) But its not quite what I am looking for. I see where your going but i am really wanting to go with a print-type look that only labels and blank space can provide. I want it to look like soley readable data. Although i completely understand that table views can be a way out, personally it makes me feel like the cells should be clicked. I don't want to give the user any impression that they are supposed to click on anything. Simply readable uneditable data. – AdrianGutierrez Aug 11 '16 at 02:24
  • You can make it uneditable by setting the property of not allowing to select anything. http://stackoverflow.com/questions/190908/how-can-i-disable-the-uitableview-selection-highlighting – Harsh Aug 11 '16 at 02:28
  • And you can remove the separators to give it a feel like its a just a view. http://stackoverflow.com/questions/26653883/delete-lines-between-uitableviewcells-in-uitableview – Harsh Aug 11 '16 at 02:29
  • I like that idea, though. Yeah I'll go with that. Thanks! – AdrianGutierrez Aug 11 '16 at 02:51