In a brand new project, I've added a button as the top component and text field below it. I have them set to fill width horizontally. I then group them into a stackview. At this point, the stackview blows everything out.
I set the stackview constraints to 0 on all four sides. The button takes up all the space. I set a constraint for height of 30 on both objects. Things look normal again.
The problem is that I can't get any vertical space between the button and textfield. How is that done when you're in a stackview?
You can enter the Spacing for the stack view members in the attribute inspector of the stack view.
Related
I have 3 buttons which I would like to center at the top of my ViewController, so that they remain centered regardless of the screen size of the iPhone or iPad. I have tried to:
Use leading space and trailing space on the buttons either side of the view controller to center them.
Put the buttons in a View and then center the view relative to the ViewController.
Add the constraints as ratios.
Use constraints on buttons.
None of these methods seem to work for me and I cannot figure out how to solve this. I have looked around for solutions but I cannot find anything that allows me to do this.
None of these methods seem to work for me and I cannot figure out how to solve this. I have looked around for solutions but I cannot find anything that allows me to do this.
It's easy to "center" the group of buttons using nothing but constraints. Here's an example:
To achieve this, I first constrained Button 2 to the horizontal center of the safe area, and I constrained it's top to the safe area's top plus 128px. Then I constrained the top of Button 1 and Button 3 to be equal to the top of Button 2. Finally, I constrained the trailing of Button 1 to the leading of Button 2 plus 100px, and the leading of Button 3 to the trailing of Button 2 plus 100px. Here's how the constraints are listed:
I'm not sure why this isn't working for you -- you didn't give us any information about how your attempt failed. The other methods you listed should also work. For example, you can certainly put the buttons inside a view and center the view in the safe area or main view.
If you want the spacing to be proportional to the width of the screen, you can use the multiplier field of the constraints. For example, delete the horizontal spacing constraint between Button 1 and Button 2, and then create a new one that constrains the centerX of Button 1 to centerX of Button 2. Next, select the constraint that you just created and set it's multiplier field to, say, 0.5. You can do the same for Button 3, but set the multiplier to 1.5. Now you'll have Button 2 centered in the safe area, and the other two buttons placed half way between the edge and center of the safe area, regardless of the screen dimensions. You can change the values to get different spacing, of course.
I think I must be missing something simple but being new to Xcode... Specifically I am coding in Swift but I believe this is more of a .xib file question. It is easy to have add and delete buttons outside of an NSTableView (like the native Mail app's Preferences->Signatures panel) but how do you integrate these into what seems to be the NSTableView itself? (more like the native Mail app's Preferences->Accounts panel) Ideally I want the option to have more than just add / delete buttons present but once I understand the process adding more functionality should be easy.
These buttons are not integrated, it's just an NSSegmentedControl aligned to the bottom of the table view.
To get this particular appearance of the NSSegmentedControl
Set Style to Small Square
Set Mode to Momentary
Set the Image of Segment 0 to NSAddTemplate
Set the Image of Segment 1 to NSRemoveTemplate
Set the width of Segment 0 and 1 to Auto
Set the width of Segment 2 to a fixed width.
The particular example you showed is just some buttons in a container view abutting the bottom of the scroll view that contains the table view. The container view draws a background to match the buttons and a border. It's probably actually "underlapping" the scroll view by a point so you don't get a doubled border between them.
In fact, if you look carefully, the container view is one point too narrow, so that its right border doesn't match the right border of the scroll view. That kind of proves that it's not part of or in the scroll view.
I also had the same question & I posted an answer here :)
But what I think is its a NSView containing 2 NSButtons for + & - as posted in my answer linked above.
I am struggling with this stuff for a few days. I am having a view controller in which I have a scroll view and above it a content view. In the content view I am displaying some text from web in a label. I am using a view controller of free form size 600*1000 for my designing purpose.I have given the following constraint to my content view -
1)pinned to the edges of scroll view.
2)content view width equals to superview width.
3)content view height equal to 900.
My scroll view is working perfect.
So now I want that whenever my text increases then my label size would increase thereby increasing the height of my content view automatically. So how to do so. Any answers are most welcome. Thank you.
Set the number of lines for your UILabel to 0.
Add leading, trailing, top and bottom constraints to UILabel.
Set number of lines to 0 does the trick, as the content increases UILabel will automatically adjust the height.
I am trying to build a screen similar to twitter/instagram profile page where there is a header section and below that scrollable content.
I have a view controller which has a table view. I wanted to include a header view on top of the table cells. So i dragged and dropped a "View" just above my cell and it works fine. Now i have a label inside this header view and i want the label height and UI view height to adjust automaticlly based on the content length of the label. (If the content is a long string, the number of lines of label should automatically increase and the container view(headerview)'s height should increased based on it's content items property.
I tried to set auto layout on the table(top left right and bottom to the container view(headerview). But then the label is shown in single line, truncated at the very right corner. If i remove the bottom constraint from my constraints, the label appear in multiple lines, but the container view(headerview)'s height is not increased, thus producing an overlap of the label on top of the table below that.
I have the number of lines property set to 0 for the label.
Can anyone share some ideas how to do this ? I am using Xcode 7 and swift 2
There are several approaches for what you want to accomplish. If you do not care if the header scrolls with the cells, the easiest way is to do something like this:
----------------
Header
Label
TableView
----------------
You should pin your header Top,Right,Left.
You should pin your tableView Right,Bottom,Left.
You should pin Header.bottom = TableView.top.
You should pin your Label 4 sides to it's superview(Header).
Set Label numberOfLines = 0
If your header has a fixed width, the label will automatically inherit that width, and setting numberOfLines=0 (a.k.a unlimited number of lines) will make your label increase it's height. Because your label is pinned to it's superView by it's 4 sides (and the header has no fixed height), your header must increase it's height to match the label height.
Hope it helps!!
I'm using Autolayout to set up quite a lot of labels and buttons in a view. One button needs to be exactly betwwen 2 UILabels and I don't know how to accomplish that. I try to get the position on one label, the position of the other, do the math, etc. But since it's using autolayout, it turns out that the frame.origin.x property is always 0.
So any clues on how to do that?
thanks in advance,
One possible way to do this using the designer is to place a container that will fill the space between the two labels. Just drag a View onto the design surface and make sure that you have the following constraints: Top Space to the top label with default value and Bottom Space to the bottom label with default value.
Once you have this container simply place the button as a child of this container and centre the button horizontally and vertically in the container. That should do it.
This could also be done with code. Let me know if sample code is needed.