Xcode 4 Interface Builder Performing Undesired Auto-resize of Controls - iphone

I'm new to Xcode, and I'm having issues with Xcode auto-resizing controls when I add them to a view. Literally every control I try to add to the view is resized to fill the entire view, and I cannot figure out how to manually resize the controls and/or disable resize to fill in the first place. How does one go about this?
Thanks for any help :)

Ah. In a fit of noobishness, I failed to realize that I was adding controls to the view controller. Whooooops.

Related

Buttons move themselves after upgrade to Xcode 5

This is something that I've brushed off for a while now, but needs to be fixed. Recently, I upgraded to Xcode 5. After the upgrade, the buttons on the initial view will move after being clicked. This only affects that view, and none of the other views. This is odd, because the main view has no attached code to it - it is just a default UIViewController class. I tried creating a custom UIViewController class and linking the view to it, and I've tried deleting the button and recreating it - but they still move when clicked. Has anyone else had this problem after they upgraded to Xcode 5?
Before I click a button
And after I click a button
I suspected the problem is with the new Auto layout and the constraints. I have had similar issues with this when an object redraws it moves. Normally mine are when I expand a NSWindow (OSX) the objects inside its view fly off into a different position.
I would suggest you read the Documentation on Auto Layout guide and then have a look at how your buttons are set up. The is also a section on how to debug issues.
This is most likely happening due to auto layout. You have two options:
Add auto layout constraints that will position them in fixed positions, so that way they will never move.
Disable auto layout for your storyboard or XIB that contains the view controller.

UIButton images look fine in IB but get stretched when displayed on app

I'm developing an Enterprise app for tracking mileage and maintenance for company vehicles. I've added graphic buttons to snazz it up a bit. The buttons look the way they're supposed to look on the XIB in IB, and on the iPhone all other UIViews look correct, but on one particular UIView the graphic images are stretched way out of proportion vertically.
The first image below shows how it's supposed to look, with the three graphics buttons at the bottom. The second image shows how it's showing on the phone. The Help button on this screen cap shows normally, but it can't be counted on to stay that way.
It also is not consistent. Calling this view at any time may show the image stretched or it may not show an image at all. It rarely shows the image normally, like the Help button looks below.
The development phone is a 4S running 6.1.3. The views are set for the Retina 3.5 screen. XCode is the latest (whatever it is).
Again, it's only on this one view that the problem shows up. There is another UIView on the same view controller that is hidden when this UIView is shown. The button graphics on the other view look fine. All of the other views and view controllers use the same graphics on the UIButton, without any problem.
In Interface Builder (Xcode) you created the view using a 4.5-inch screen height.
But the device where you are seeing the problem is a 5-inch screen. So the view is resized to fit.
And when it does that, the autolayout constraints that Interface Builder put on those subviews take over to determine what they do. Those constraints are causing the heights to change.
No need to turn Autolayout off. Autolayout can be very useful, but it seems to enjoy randomly assigning the constraint "Align Baseline to:" to UIButtons after repositioning them.
Just select the UIButton/UIImageView in question inside Storyboard, locate the constraint "Align Baseline to:", tap the gear icon and select "Promote to User Constraint", and tap once more and select "Delete". This should solve your issue.
In response to the comments here, I will answer my own question: I turned Autolayout off for this view controller, and that fixed everything. This is the first app I have written since XCode has begun development for the iPhone 5, so I wasn't aware of the Autolayout feature. I'll need to understand how it works and why it did what it did.
Thanks for all your help!

How do I lock text fields and images in place in ios?

When I am designing the interface everything looks fine.But when I run the project some text fields move and get mixed with other text fields.Some images go down.How do I lock everything in place ,so that the gui is exactly the way I designed it
hi iOsBody there are some layout problem is bellow Tips you can set properly.
in your issue you have use UINavigationController in every viewController but when you set XIB layout you can not add this 45px UInavigationBar space in XIB that's why you facing this issue.
while you use this in ios6 You can also use AutoLayout but its some time getting Creshed in ios5 or bellow ios
So please check proparly x,y and also put calculate px of UInavigationBar or statusbar while create Interface.
You can fix property of Textfield & image. So, it'll not move anywhere & stay at their own places.
Hopefully, it will help you.
Thanks.
If your view using AutoLayout functionality than uncheck it.
see the option Use AutoLayout in your main view .
1)this will help u auto size the components

Scrolling through UIScrollView in Interface Builder for Xcode 4

This seems to me as though it would be a common problem, but I can't seem to find the answer anywhere. This question seems to address the issue, but I can't seem to get the solution to work and I'm not sure it's referring to Xcode 4.
When using Interface Builder in Xcode 4 and working with a UIScrollView, is there a way to scroll the view down in Interface Builder itself to view/add/edit controls that are out of the viewable section of the screen? I've managed to push a couple controls down using the arrow keys, but now I can't see them and therefore can't manipulate them in Interface Builder. Scrolling the view in IB would be first prize, but if there's a way to even select the controls using a drop-down menu or whatever so I can push them back up with the arrow keys, that would at least be something. Thanks.
Set the ViewController's Simulated Size to Freeform and set a very large height. E.g: 1000 and voilĂ ! You can now scroll to see all the stuff and add even more! :)
P.S: Remember to set set Fixed when you are finish to avoid problems!
Just a workaround which helps in Xcode4:
Expand the Objects Panel which resides on the left of the Interface Builder view (there is the tiny arrow at the bottom of the panel).
Drag your UIScrollView from the view hierachy and place it on the top level.
Now you can resize it to access more content (scrolling to that content did not work for me).
When you are done adding child views to the scrollview, you need to resize it back to be smaller or the same size as the parent view.
After your changes you would need to put back the scroll view where it belongs in your hierachy
I typically do the following when I want to (have to) build a long scrolling screen:
Set the size of the View Controller to Freeform
Set the height of the top level View to something very large
Arrange all the controls that I want on the View
Select all the controls
Select Editor->Embed In->Scroll View
Set the size of the View Controller back to normal (typically Inferred)
Well, there are a few different things you can do. There is a list of items in your view you can open on the left of the workspace by clicking the button that looks like a little play button on the toolbar. Double clicking any item selects it so you can use the arrow keys.
The best option is to use the layout panel (typically on the right) and enter position values manualy. Sometimes I will use this to move my scrollview up to where I can see where I'm working then move it back.
I found a solution although you have to use a Table view controller. If you define the table as static, the scroll works in interface builder when the table is bigger than the windows size. Moreover, a standard view can be added to the top and bottom of the table, these views are scrollable as well. The scroll is made once the controller is selected. I hope you find this trick useful.
I know this isn't exactly what you were looking for, but I always just drag the scroll view out of the view controller onto the "pasteboard" where you can resize it at will and see the whole thing.
Once I make my edits I simply resize it to fit it's allotted space in my view and place it back in the view controller.
set the root view to freeform and ~1000 pt height, go through the child views and set them to this height as well(including scroll view), in the viewdidload method set the height to the appropriate size.

UISegmentedControl not expanding size for navigation bar/very squished

Running through an iPhone SDK book and one of the examples has me creating a table and then later adding a UISegmentedControl to the table for sorting.
I dutifully did this in IB, and it looks great:
IB Screenshot http://img.skitch.com/20100529-83sefni21q4nj51rw1mghh2yj1.jpg
When I run it in the simulator or my phone, it's totally squished:
Squished http://img.skitch.com/20100529-x3pmr7gkb6xpm766bupi7quy55.jpg
The buttons work perfectly, it's just they are not sizing according to their content. Any ideas what's going wrong?
Here's the attributes I have set:
Attributes http://img.skitch.com/20100529-tp4d69bk8x98c6sjpmcne92etb.jpg
You could try explicitly setting the width of each of the segmented control's components. Click the Size tab at the top of the inspector and set the width for each component.
I experienced the same issue once. The problem was that the UINavigationController's view was not the top-level view in the hierarchy (it was not added to UIWindow directly), but it was added as a subview to another view controller's view instead. It's just a guess, maybe that's your problem, too (or that there are more than one visible view controllers).
OK, so in attempting to implement #Chris Gummer's answer, I seem to have learned more about how the Size->View Size property panel works. The default is:
Default Sizing http://img.skitch.com/20100529-gg9dwq5em3557yb1d6d721hpn4.jpg
and this is not a good default, it would seem. My book didn't mention needing to adjust this, so I didn't look at it. Setting the inner horizontal arrow of the box (which I guess means "fit width to available space") did the trick:
The Answer http://img.skitch.com/20100529-xt1bqghb4kbm2pbcqf1i1uygab.jpg