0

I have the following detail screen:

Detail Screen 1

When you scroll:

Detail Screen 2

I have the problem that some of the fields are truncated at the end because there is more text than it shows. Right now the detail screen is built with multiple labels as follows:

Layout Xcode

For some fields like the description I used a text view. If the description is longer I move the labels (this are inside another view) below so that the description field is showed completely. I have to do this in the behind code with lots of calculations. Since the designer is not able to tell the control that the Training Type label should always be below the description even though the description field incremented its height. The blue area at the bottom is a scrollview with a segmented control that scrolls horizontally, this is static it does not have to do with the data that comes from the database.

Here is another example of the designer:

Xcode designer

This may not be the best solution but at the time it work for what it was needed.

Is there a better solution for this detail screen? Something that do the dynamic height of the fields automatically when the data is assigned?

This data comes from the database and not for all records the amount of data is the same. They all include all the fields shown here but not always completely full.

5
  • 1
    You could use an UITableView with a custom cell, where you can just set the title and value. You can create some kind of object that holds these values pass them to the date source and display them.
    – rckoenes
    Aug 8, 2013 at 15:06
  • What versions of iOS do you need to support (auto-layout)?
    – Wain
    Aug 8, 2013 at 15:10
  • @Wain I need to support the latest iOS version.
    – Angie
    Aug 8, 2013 at 17:21
  • I mean, what older versions. Can you do iOS 6 only?
    – Wain
    Aug 8, 2013 at 17:44
  • Yes, its going to be iOS 6 and up.
    – Angie
    Aug 8, 2013 at 18:23

1 Answer 1

1

I think this would be easier to carry out with a table view in a UIViewController (not a UITableViewController where the table view would take up the whole screen). You can use UILabels, with number of lines set to 0 so they can expand vertically when needed. If you set up the layout constraints such that the label is tied to the top and bottom of the cell, the label will expand when the cell does. Use tableView:heightForRowAtIndexPath: to adjust the height of the cell based on the data for that row.

2
  • How would the cell knows when to expand its label?
    – Angie
    Aug 8, 2013 at 17:28
  • 1
    @Angie, You calculate it based on the size of the string for that indexPath (using sizeWithFont:constrainedToSize:lineBreakMode:).
    – rdelmar
    Aug 8, 2013 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.