2

I'm trying to recreate the default viewForHeaderInSection only with a button in each header, using autolayout. The crux of my layout is:

@"|-[titleLabel]-4-[refreshButton(==22)]"

This works just fine in both portrait and landscape on my iPhone.

enter image description here

However, when run on an iPad, the 'titleLabel' is too close to the left margin (because the margins are larger on the iPad). I had hoped that |- would use the standard margin to position the label, but it seems not (I guess it just uses a default number of points).

enter image description here

How can I position this label correctly? Do I need to check for iPad vs iPhone and update a constant? Or can I refer to some constant value that represents the margin size?

Ben Packard
  • 26,102
  • 25
  • 102
  • 183
  • Seems to be this one: http://stackoverflow.com/questions/4708085/how-to-determine-margin-of-a-grouped-uitableview-or-better-how-to-set-it – Valent Richie Jul 02 '13 at 08:48

1 Answers1

0

You should add a new constraint which aligns the left edge of the titleLabel to the left edge of the UITableView. In IB/Storyboard, this is easily done:

  1. Select both objects
  2. Click the alignment button (the first one in this image: enter image description here)
  3. Click align Left Edges
Rick Pastoor
  • 3,625
  • 1
  • 21
  • 24
  • You would think so - except in a UITableViewController: "'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal." – Ben Packard Jul 11 '13 at 20:15