I am working on IOS app which got a UITabeView. I needed custom UITableViewCell, so i created .xib file to design it and linked it to my custom class. But I want a button to be aligned right and I cannot achieve it. The screenshot below shows my problem:
I am using autolayout. On the left side I have my .xib opened where I have a button. In the middle there is a simulator which show only a part of a button. Moreover, If a change orientation, absolute button position doesn't change (it becomes fully visible). On the right side you can see how I set constraints. Obviously, I did it in a wrong way, but I've tried everything and nothing helped. Different constraints, values, toggled autolayout - no effect.
How do I set up constraints so that my button is aligned right (on both orientations)?
P.S. I am using Swift.
you have to link your button to the view which contains it, you can press Ctrl and drag the mouse from your button to the view which contains it, Xcode will show a menu with the available constraints:
You have to select the constraints you need for setting up the position of the button, in your case it will be leading space to container, and in addition you should select width and height constraints. For selecting those constraints you can press this button on the bottom of the screen:
and in the following menu select the width and heigth constraints:
Hope it helps!
Related
This is my first swift application, so apologize if it's very basic. I was unable to find it...
In my view, I've a Navigation on top (Navigation Controller) and It's using a TabBar Controller. I'd like to make the TableView fill the whole empty space no matter the size of the device nor orientation.
I set the property Content Mode to many different options, including Aspect Fill, but all the options can't cause any effect.
Any clue about it ?
First make your tableview completely fill the screen and then set the constraints to be in 0 margin from all sides, like in the image
use constraints for display full table view on empty space.enter image description here
Click on pin icon from bottom side of Xcode.
Select all for four(up,down,left,right) constraints and set 0 value for all.
after then click on add constraints button and refresh frame(click on right side button of Pin button and select Update Frame).
I am a beginner using Xcode 7 beta, working off a tutorial that uses Xcode 6. In the tutorial, the instructor selects Editor, Pin, and Horizontal Spacing to pin the space between two images so that it stays the same when switching to landscape. In Xcode 7, the Editor menu doesn't include a Pin menu. Does anyone know how to pin horizontal spacing between two images in the new Xcode 7?
This is close to what you need
You can choose View (current distance = 0) from the drop down menu
Use the pin button at the bottom right corner of the storyboard view. It looks like a Tie-fighter icon.
You will also notice that Pinning two elements to each other for horizontal and vertical spacing is not there. Instead select the left item and add a right constraint. Then select the right one and add a left constraint. You will see the horizontal spacing indicator appearing between the two. YMMV.
EDIT
If you are going thru the same tutorial (RW) as I am going thru, fear not! The control-drag between elements still works the same and brings the options XCode 6 shows in a similar way (ex: ctrl-drag from left to right way brings a popup menu with horizontal spacing.) I hope this helps.
Just to kind of clear this (good) answer up - select the left image, then the "pin" icon (tie fighter looking thing), click the right constraint icon at the top that looks like this:
|--|
...leave the value of it where it is. Then click the "add constraints" button. Do the same for the right image. Then run the app and verify that it works.
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).
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.
Why is the Button object not available in that menu?
How should I add a constraint between the Text View and the Button?
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.
I have a web view inside a tab bar controller. The problem is when using the web view, the content goes behind the tab bar and I cannot scroll to the bottom of the page. How do I resolve this?
Here is how everything is setup in Xcode
If you are using AutoLayout set the constraints of the UIWebView so that it is attached to all the sides.
Edit: Instructions
Select the UIWebView
Select the icon shown in the picture below
Unselect the Checkbox for "Constrain to Margins" because we want to constrain to neighbor
Set the numbers around the center square to 0's
Click the icons that are between the middle square and the numbers you just changed
Click Add Constraints
I have a button that needs to "stick" to the bottom of the main view on both 3.5 inch and 4" iPhones. Currently, I can move it right to the bottom of the storyboard on a 3.5" view but then on a 4 inch view, it moves up.
How do I stick the button to the bottom of the view on both screen sizes?
Select your button which you want to pin to bottom. Click on add new constraints and select bottom constraints then click on add.
Use AutoLayout feature.
While you're laying UI components on the screen, you see some blue colored guidelines, those are just helper lines and have no effect whatsoever when you actually run the program.
Once you're done with placing all the UI components on the screen, you have to actually set the constraints for the AutoLayout using the few buttons that are placed in the bottom right part of the Storyboard view.
Is suggest that you right click on the Storyboard view, and go into "Interface Builder Help" option, and then click on "Understanding Layout Constraints" and "Aligning and Pinning Objects" to see how constraints are actually set.