0

Using xCode 4.6, I have a toolbar at the top of my view that contains 2 buttons, followed by a text field and two more buttons after that.

I have set the buttons to be equal size and I can drag the width of the text field so that the full width of the toolbar is being used.

This looks good in portrait, but for landscape I get a lot of white space after the last item.

How can I set the text field as if it was "width 100%" so that it would expand to fill up the toolbar? Or how could I cause the width of the item to change when the screen is rotated?

I'm new to xCode! So most of my work is not written programmatically. Many helpful tutorials I use refer to a different version of xCode so can be tricky to follow.

omz
  • 53,243
  • 5
  • 129
  • 141
Patrick Keane
  • 663
  • 3
  • 19
  • 41
  • 2
    Are you tilting your iMac or MBPro to check if its working good? – Anoop Vaidya Apr 15 '13 at 17:07
  • What? tilting your iMac or MBPro? – Patrick Keane Apr 16 '13 at 08:29
  • As you said, toolbar of xcode? that was a joke. I guess you must be asking for ios.iphone? – Anoop Vaidya Apr 16 '13 at 08:30
  • OK! I never indicated what device!! I'm basically developing a WebViewer for iPad. The toolbar at the top has an address text field and I want to set widths on the address field for landscape and portrait mode so that it expands to the full width of the toolbar. – Patrick Keane Apr 16 '13 at 14:07
  • your tag should look like this. :) – Anoop Vaidya Apr 16 '13 at 14:29
  • If you don't have anything constructive to say then leave this space free for someone else! – Patrick Keane Apr 16 '13 at 15:20
  • There are 2 ways. 1st. change the view itself (Make two views on for landscape other or portrait). 2nd. Use autolayout, [read1](http://www.techotopia.com/index.php/Working_with_iOS_6_Auto_Layout_Constraints_in_Interface_Builder), [read2](http://iphonedevsdk.com/forum/iphone-sdk-development/109628-programatically-change-autolayout-on-orientation-change.html) – Anoop Vaidya Apr 16 '13 at 16:27

2 Answers2

0

You need to set the landscape image using this method:

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage: landscapeImagePhone: style: target: action:]

That, or as another user stated, you can use the (not friendly to older devices) autolayout.

jakenberg
  • 2,125
  • 20
  • 38
0

It doesn't look like you can set horizontal spacing constraints on a toolbar. The best way to do this is probably to check the orientation when you load and set the width accordingly. You will also need to set it when the orientation changes. That code should go in willAnimateRotationToInferfaceOrientation.

mimc
  • 111
  • 1
  • 7