Trying to understand Auto Layout - xcode

I'm trying to understand how to use Auto Layout but I haven't been able to wrap my head around how to accomplish something like this using it. I have an iPad ViewController with two subview views. I'd like the layout to work like in this representation but I'm not clear on which values to set. particularly the relationship between the two subviews:

The left view should be pinned to the superview's top, left and bottom edges (with your padding) It's right edge should be pinned to the right view's left edge.
The right view should be pinned to the superview's top, right and bottom edges (with your padding). It should have a width constraint with a constant value, which you would set to the appropriate number on rotation.
In IB, you'd create an outlet to the width constraint. In code, just assign it to a property as you create it.

Related

Cocoa Resizing Two Stacked Tables

I have a view with two vertically stacked Table Views. When I resize the application window, the lower table view expands. This is because I didn't specify a height for it. It has a fixed distance to the bottom of the window and a fixed distance to the table view above it. If I attempt to remove the fixed height for the upper table view, the constraints editor complains. Is it possible to have both table view expand equally when I resize the application? If not, is the possible to allow the upper table view to be resized when the application is running?
I found a way to do this as long as there is some sort of control between the two tables. A label will work fine. Using constaints:
For the control in between the two tables, set the Alignment constraint to "Vertically in Container. This will perfectly center the control. You can offset it above or below center by adding a positive or negative value in the combobox next to the option.
For the top table, pin the top of the box to the top of the window or any other place that fits your design.
Set the bottom constraint to some offset from the control in step 1.
Set the bottom constraint of the bottom table to something fixed like the bottom of the window.
Set the top constraint to some offset from the control in step 1.
Be sure not to set the height of either table.
When the window moves vertically, the control in step 1 will be moved to keep it in the center plus or minus any offset you provided. The two tables will be expanded or contracted accordingly.

Align a view to the right (appcelerator alloy)

I am trying to align the view to the right, I tried
right="0"
I tried getting the width on the controller and subtracting the view size and no succes
<View id="logoutAlignRightContainer" layout="horizontal" width="33%" heigh="40dp" right="0">
<View id="logoutAlignRight" left="" width="72dp" height="40dp" right="0">
<Label left="3" class="button" onClick="logoutEvent" width="Titanium.UI.SIZE">Log Out</Label>
</View>
I want to layout the $.logoutAlignRight to the right, but it stays at the left
You need to remove the layout=horizontal from logoutAlignRightContainer. By adding that you force the child view to layout starting from the left...
The answer for your question is Composite layout, please read the below basics:
There are three types of layout in Titanium (let's suppose there are 3 child views A, B, C):
composite (default) - It always keep all child views at its center position, and that's why you can always use any of the property like left, right, top, bottom.
So, A, B, and C will be at same center or on top of each other.
If you set only top and bottom, then it will only determine the height of view.
If you set only left and right, then it will only determine the width of view.
vertical - It aligns child views in a stack form, one below another. Still you can use left, right, top, bottom, but you will find setting left and right property easy, but top and bottom properties might not behave as you expect because top and bottom will behave in relation to the other child views.
So if you set left or right, view will be left/right aligned staying in accordance with the stack form.
If you set both left and right, then it will be the width of view.
If you set top, then it will be counted from the parent's top edge.
If you set bottom, then there will be bottom space of same value but the child view will still be there at the top or at the corresponding position in the stack.
horizontal - Aligns views from left to right.
If you set left, it will add space to the left edge of view.
If you set right, it will add space to the right edge of view still keeping the view aligned from left, so its useful when you want to set the width of view in horizontal layout.
You should try these layout basics so that you can save your valuable hours in further development and soon you will be able to design efficiently. Titanium Docs are of great help.

How to ensure NSOutlineView inside a custom view renders full height (without scrolling)

I have a window with two custom views stacked on top of each other. I use auto layout constraints, as follows:
Top view leading, top, and trailing edges are tied to superview.
Bottom view leading, bottom, and trailing edges are tied to superview.
There is a fixed vertical space constraint between two views.
Bottom view has a fixed height constraint.
Top view has a it's compression resistance set to 751.
So far so good. The idea is that the bottom view height is fixed and as the window is resized, the top view height adjusts to compensate.
Both top and bottom views have other views/controllers loaded in, as appropriate. The bottom view ends up containing an outline view with a half-dozen entries. I would like that outline view not to scroll. In other words, I would like to automatically adjust my bottom view fixed height constraint to match the height of the outline view required for it not to scroll.
Ideally, I'd prefer to solve this with auto layout without having to write code. But, if that's stretching beyond what auto layout can do, code help would be appreciated as well.

Superview not resizing with subviews

I have a window into which I horizontally add two subviews. Into each subview, I place a variable number of subviews made up of a vertical slider, a text field rotated 90 degrees and placed to the left of the slider and another textfield, placed just under the slider. The slider subview's constraints are done in code, the parent views are both done in IB. When I add more slider views to the left window than the subview can handle in its default size, it resizes horizontally and forces the window's content view (and window) to also resize horizontally. Great, that's just what I want. But if I add more slider subviews than can fit in the right subview, they just get squeezed together and the subview does not expand as the left. I layout the slider views using code with this category converted to support NSViews, instead of UIVews:
UIView+AutoLayout1: https://github.com/jrturton/UIView-Autolayout
The constraints for the left and right subviews are more or less the same. I can't figure out why the right view does not resize as the left view does.
Here is a link to a sample project that demonstrates the problem:
SliderTest
Some someone help me out with this?
Also, a secondary question as I think my slider view could use a little work:
When a view is rotated using setFrame(Center)Rotation, do the top, right, bottom and top edges remain along the same edges or do they reflect the new orientation of the rotated view?
Thanks
I found the problem. The constraint between the left view and right edge of the window was fixed at 233 instead of >= 233. I had this at some point in the past, as I was adjusting the constraints to achieve the desired behavior and just overlooked this one through the troubleshooting process.

Positioning a UIView between two other views. Autolayout

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.

Resources