Xcode not respecting the constraints on my iphone xib file - iphone

I am having problems figuring out why Xcode is not respecting the constraints on my iphone xib file.
This is how I set a button in the xib file:
and this is how it appears in the simulator:
and this is how it appears in the simulator:
I defined the size of the button:
Any of you know what I'm doing wrong?
I'll really appreciate your help.

If you want the button to stay at the center of the view, you just need two constraints.
vertically center in container
horizontally center in container
Add this two and get rid of the vertical space containers.

Don`t no much about constraint but u can remove it with Doing uncheck in AutoLayout in property editor.
And than palce your button and make it center horizontal and center vertical from property editor of xib.
And make all bounds pack in AutoSizing given in property editor.

Related

Make a horizontal NSSlider vertical in Xcode

I'm fairly new to Xcode and Swift. I dragged a horizontal NSSlider from Xcode's Object Library onto the View Controller of my Storyboard. Now I realize that I probably would have been better using a vertical slider. Is it possible to change my current slider into an actual vertical slider easily, keeping the max and min values, connections to my ViewController.swift file, etc. without having to reconfigure them?
I don't want to programmatically change it; I want it to be a static vertical slider.
I realize that in the documentation there is an isVertical variable to make it vertical, but that's not what I'm looking for. I want to it be vertical on my Storyboard, and be able to move it around – I don't want it to become vertical when viewDidLoad(). Actually I tried that out of curiosity and it didn't do a great job changing my horizontal slider into a vertical one.
Interface Builder derives the horizontal/verticalness of the slider based on whether it's wider or taller. So you can change this by editing the frame size of the slider to have a larger height than width.
One way do this is to view the storyboard document source (right click the file, Open As ▸ Source Code) and flip the width and height of the slider, e.g.:
When you open the document back as an Interface Builder Document, the slider will appear and act as a horizontal slider.
You can just drag a Vertical Slider in storyboard and remove the Horizontal Slider

How to change searchBar width programmatically? (Swift)

I'd like to resize my app components when device is turned into left or right side - when it keep horizontal position
I'm checking device rotation in willRotateToInterfaceOrientation event and then I have to change width of searchBar and tableView. How should I do it? I tried some variants with components .frame and with CGRect, nothing works.
Update:
it can be done without any code. View my answer below
If you laid out your elements in Interface Builder then you can just add an outlet to the width constraint of your search bar. Then, change the constraint's constant property to change the bar's width.
I found the way to do I need
So, the task is that components will be resized in width when device turns horizontally.
1) Select items must be resized
2) Select "Leading Space to SuperView"
3) Without unselection, select "Add missing Constraints"
That's it. Now they will be resized correctly

iPhone 4 & 5 Autoresize Vertical Space

I built my views in Interface Builder for iPhone 4 dimensions. I thought that the Autoresize Constraints in iOS 6 will take care of the resizing automatically. The screenshot shows the Top Space constraint that Xcode added automatically. It says that the relationship between the top and the bottom orange view must be 332 points.
When viewed in iPhone 5, the orange button is stretched all the way to the bottom as you can see in the screenshot below.
When changing the relation to Greater Than or Equal, the view does not change and remains the same. When removing the constant to make it Auto, the view is stretched across the entire screen. How do I specify a constraint were the height is 44 points and at the bottom?
Don't have a constraint to the top of the superview. Pin it to the bottom of the superview, and fix the height to 44, then delete the constraint linking it to the top of the view.
You achieve the pinning by selecting the view in question and using the pinning menu in interface builder (the floating menu with three icons on it, or editor-->pin from the menu bar).
To move between 3.5 and 4 inch displays, you need to link content to the correct edge of the superview. Stuff at the bottom should be stuck to the bottom.
I have written about constraint editing in interface builder here if you're interested.
Try adding your own contraints (user constraint), In Auto Layout for each object there must always be enough constraints to determine both its position and size on different devices screen.
Interface Builder automatically creates constraints for you as soon as you place a view in a layout. Try placing your views along IB’s automatic guides to help it guess correctly which layout you want.
Prior to Xcode 4 it was done by setting the springs and struts from the Interface Builder and the springs and struts model is still the default, so for every programmatically created view that you want to use autolayout with, dont forget to call
setTranslatesAutoresizingMaskIntoConstraints:NO.

I added UIButtons to my app and made custom images for them, but when I run the app in the simulator, my buttons are severely stretched

This is what the storyboard looks like in Xcode
This is what it looks like in the simulator
Does anyone have any idea why this may be happening?
Check that the autolayout constraints for each button are setup properly. i.e. your top left button should probably have a constraint for its width and height and should pin its leading and top space to its superview.
Try resizing your images to the frame size of your UIButton and generate an #2x copy for your retina display. You can also try setting the mode to aspect fit in the attribute inspector.
I deleted the buttons and re-added them, and now it's working well. Thanks for the insights.

MKMapView maximized, but I do not want it

I got an issue and I don't know why I have it and how to fix it! Maybe it is only a simple problem. Here are two screens:
There is something missing! Where is the Button? And why is the Map at full screen? It seems a bit strange can anyone help?
This is undoubtedly a function the screen going from a 4" screen when previewing your screen in Interface Builder to a 3.5" inch simulator/device screen.
If using autolayout (open up the storyboard, click on the first tab, the "File Inspector" and see if "Use Autolayout" is checked or not). Check your constraints. The map view should not have a height constraint (or if IB won't let you get rid of it, just drop its priority down to the lowest possible value...though if it adds the height constraint back in, it means that your other constraints are not fully qualified, such as neglecting the button's bottom constraint) but should have either a bottom constraint to the bottom of the screen or, better, to the button. Also make sure that the button's top constraint goes to the map view and that it has a bottom constraint that goes to the super view. Interface Builder makes this process far more complicated than it needs to be in its effort to add what it determines as missing constraints, IMHO, but it can work. It took me 2-3 minutes of fussing with all of the vertical constraints to make sure that they were both unambiguous as well as satisfiable at both screen heights.
If not using autolayout, check your autosizing masks (located on the "Size inspector" tab). You want flexible height and fixed bottom.
In IB you can toggle the appearance of your view from 4.0" to 3.5" by pressing the button. Just adjust your autolayout constraints or non-autolayout autosizing masks and then toggle back and forth between 3.5" screen and 4.0" screen to confirm whether everything is configured properly.