can't move button in view controller in Xcode - ios

I have created a new view controller in Xcode and added a button . I am trying to add constraints to it to move it to top left hand corner of screen , but all the constraints seem to be disabled.
Also when I am trying to add a second button to the view controller , it replaces the first one rather than adding a second one.
Control and Dragging the button shows the following menu, instead of the adding constraint menu
Can you point me towards where I am going wrong ?
PS: I am new to using Xcode, so kindly let me know if I need to provide any further details to make it easier for you guys to understand the issue.

First of all you need to put button wherever you want and then press button Resolved auto layout issues (Second from the last) at the bottom right corner and select add missing constraints.
And second you can manually add constraint to this button as
To do
You need to Control + drag from button to superview for leading space, trailing space, bottom layout and top layout constraints.

Guys thanks for your inputs . I found the issue , the button wasn't on any view , hence when I was trying to control drag i was getting those options. I deleted the button , added a view and then added a button . All good now.

Related

NSAutoLayout, View , Tableview

I am working on a client app, with a screen that has one top view ands a uitableview. I am new to iOS and NSAutoLayout, I used the recommended settings from xcode, and ended up with something that looks like this in interface builder
But when I run this in simulator I get a weird space seperating the tableview and the top view, like this
Where is this space coming from ? how can I fix this?
update :
there is one constraint for the tblview, its basically that height = 500. could that be the issue? can I make that more dynamic? I am after all new and used whatever xcode recommended!
coupe of things:
set leding, trailing n bottom pins for tbleview to 2.
set verticl spcing between tbleview nd custom view to 2.
set leding, trailing n top pins for custom view to 2.
set verticl spcing from custom view to bottom lyout to 548.
Screen shot:
then run on simultor:
hope it helps
Edit
Just select custom navigation view and add pins by selecting second menu option from available 3 options.
There will be a check mark "margin" just uncheck it. Select left right and bottom and add constraints.
It's really painful answering from iPhone dev typing

Extra space on top and bottom of Init View Controller

I have a swift app I have been working on for some time now. I noticed that my init view controller has extra space at the top and the bottom of the view, so much that it allows me to pull up and down on the first view and let go and have it spring back into where it was. I removed all my constraints thinking I had an issue with them, but it's still done the same thing. The size class is set to any any, and all my graphic fit inside the view, yet I still an able to pull up and down.
I also made sure my view, wasn't a scroll view, it's not.
I looked around for similar issues, but couldn't find anything like this.
Thanks for the help!
Here is what my view looks like in IB
When I run the app.
Showing the amount I am able to pull it down from the top.
If you remove all of your constraints, and the storyboard is set to use auto layout, it usually won't show up correctly, as you have seen. You will have to add the constraints to each element in your view controller. To do that, you can control click on each and drag it where you want to connect a constraint. Or, use the pin and align buttons in the bottom right corner of the storyboard view.
There is a good tutorial from apple that I suggest you read. It will help you with the basics of using auto layout. Another option would be to not use auto layout. To turn it off in the Storyboard, go to the file inspector and uncheck the box "Use Auto Layout".

Update constraints menu all greyed out

When I try to update constraints in Xcode 6.3, I can't because the menu is completely or partially greyed out.
http://hostthenpost.com/uploads/aa150beda71316c338da81c5e301d149.png
Why is this? How do I fix it? The app is a basic, simple Hello World app with two UIImageView elements both sharing heights and widths, and one is constrained 50 from the left, the other 50 from the right. What is wrong with it? How to I make it so I can update the constraints?
Edit: This is when I can see some, but not all of the constraints options.
http://hostthenpost.com/uploads/2d8a3bec6a17524d6f9ca1524c95fb0c.png
That happens when you have a wrong item selected, meaning for example a constraint instead of the view or a subview.
To fix it, just select the view again. Then the options should show up again.
Still some options will be grayed out, if they would have no effect when clicked. For example Update Frames will only be available if there are actually are frames to be updated.
If you clicked on the main view and then on the constraints button, you have to know that you can't adding constraints from the main view in the storyboard, to its superview. You can do this just by code.
If you are trying to change the constraints for any other subviews, please be sure to click with the mouse on the object in the view, and then on the constraints button.

Hiding button leaves whitespace instead of dropping down top button in ios

I am hiding the second button below, but I want the top button to drop down. Is there a way to do that where it has a relative layout.
Yes you can do this. One of my project I had to do this. If you are using autolayout then you can not manually change your buttons frames. You can either have to disable autolayout, or modify the constraints programmatically. I followed the first one.
In your case, if you want the first button to take the position of the second one (which you are hiding) then take the frame of the second button and assign it to the first button.
Hope this helps. :)

Placing a control over a mapview iOS 7 using storyboards

I'm trying to place a button over a mapview. In storyboard I have it as the last control in the view hierarchy, the map view still covers it up. I've tried adding this line in my viewDidLoad method to bring my button view to the front but it doesnt seem to work either
[self.view bringSubviewToFront:self.flagButton];
anyone have any idea why this wouldnt be working? the map view covers most of the screen, and I want to place a few buttons on top of the map, but so far can't get them to show up, they are under it every time.
I was able to do this by making my view as subview of map view.
first,
self.view = self.gmsMapView;
then,
[self.gmsMapView addSubview:_myBtnView];
I know this is an old post, but I'm answering for the sake of someone facing the same problem.
I was having the same issue, then I found a solution, and is as follows:
First, open your project and go to your StoryBoard then click on "Show Document Outline" switch that is on bottom left very small switch. After that select your "Scene" that you are having problems with then click "View". Find your MKMapView object and drag it up until you reach the first row. This will make your MKMapView object (or any other) "the first in a layer" so to speak.
I hope someone will find this helpful.
E
I was using storyboards and was not seeing the button. I had to set the MKMapView to hidden until the button was displayed and in position. Then I set the MKMapView to visible.
Here are the steps I had to take in the interface builder to get my button to show
Create a UIViewController which contains a view
Add an MKMapView and set constraints
Add UIButton in the same view as the MKMapView, set the image and text, whatever is applicable. If MKMapView disappear when you try to resize or move the button, the map view has just set its width and height to zero. Enter new values in the Size Inspector for the map view and it will resize back. Or you can move the button elsewhere off the MKMapView and then move the button back to where you want it.
The important part is to set constraints for the UIButton. I also had to set the MKMapView hidden until I got the size and placement right and then set it back to visible.
Here's how it looks in the simulator
You can't add a subview to an MKMapView via the storyboard. Add it as a sibling view instead.
Edit: Your map view should also be a subview of the root view (i.e. self.view) for this to work.
I was having similar issues and I did the following:
Made sure both the map view and the button are at the same level in the view hierarchy, I accomplished this by creating a View that both the map view and button were children of.
Made sure the button is dragged below the map view in the left gutter of the storyboard (so it is actually rendered on top).
Made sure there were valid constraints for the button.
The only thing new that hasn't already been mentioned was double-checking the constraints, and that appeared to resolve it for me. Hope that helps.

Resources