3

The Apple guide "Adding Auto Layout Constraints with the Pin and Align Tools" states:

To create a constraint related to another item that is not the nearest neighbor, click the black down arrow in the text field and choose another nearby item from the pop-up menu.

https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/pin-constraints.html

My Storyboard has a UIView containing a UITextView and a UIButton.

I'll note that these objects are not visible "on the storyboard" in a view. They're only visible in the left sidebar due to the limitations of Interface Builder. So I cannot place the button "to the right" on the storyboard by default (if that's what's causing this problem).

View containing a Text View and a Button

I need to add a constraint between the Text View and the Button. The Text View should be on the Left, followed by the Button, with a Margin between.

However when I add a constraint, the two objects used are the Text View and the parent UIView. Not the Button.

The "nearest neighbor" of the Text View should be the button.

I'm also unable to select the button as the second item from the menu, as the guide advised. Only the parent UIView is available.

Button is not available in the menu

Why is the Button object not available in that menu?

How should I add a constraint between the Text View and the Button?

pkamb
  • 33,281
  • 23
  • 160
  • 191

1 Answers1

6

The views only show up that make sense for the direction you chose. So, if one view is above another, and you choose the left or right constraint, the other view does't show up. If you choose the top constraint, it should.

Another way to do this is to control-drag from the text view to the button in the scene list, and choose the constraint you want from the popup window. After you create the constraint, you can edit it to change the value if you need to.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • This appears to be it. The "only show contestants valid for the direction you choose" heuristic is rather useless for cases such as this where the objects are not visible on the storyboard. Control-dragging between the objects in the left sidebar allowed me to set the desired constraints. – pkamb Jun 03 '15 at 19:36