OS X Autolayout - Arranging views around main view - objective-c

I want to arrange eight views around one main central view so that as the main view is programatically moved or resized, the surrounding views keep their same positions. This link shows the layout.
http://homepage.ntlworld.com/bernie.w/Autolayout.png http://homepage.ntlworld.com/bernie.w/Autolayout.png.
Note:
Views 2 & 7 are vertically centred on the main view.
Views 4 & 5 are horizontally centred on the main view.
I'm new to autolayout, so any pointers how to achieve the above appreciated.

Just add horizontal spacing constraints between 4 and Main view then 5 and Main view. Then add vertical spacing constraints between 7 and Main view then 2 and Main view. You should then be able to do vertical spacing 'greater than or equal to' from 1 to 4 then do horizontal spacing 'greater than or equal to' from 1 to 2. Repeat that 'greater than or equal to' process for horizontal spacing and vertical spacing for the 1-3-5, 5-8-7, and 4-6-7 views and you should get the result that you want. Let me know if you have any questions about that.

Related

NSCollectionViewGridLayout in a single row with resizable collection items which maintain an aspect ratio?

I have a NSCollectionView which uses a NSCollectionViewGridLayout to create a single row of collection view items. The row can have one or more items and can scroll horizontally is needed, i.e. one row, unlimited columns (one item per column).
The collection view items have a minimum size of 240x160 and have an aspect ration constraint of 3:2 (the width is 1.5 times the height). There is no maximum size.
All the spacing/insets are set to zero so that the items are next to each other horizontally, starting at the left-hand side of the collection view (though ideally I'd like to center the items horizontally if the total width of the items is less than the width of the collection view.)
The collection view is in the top half of a split view. When dragging the divider up/down (vertically), I'd like to resize the collection view items while maintaining the aspect ratio. The problem is that the aspect ratio constraint conflicts with the leading/trailing constraints and causes a constraint exception.
1) I've tried removing the leading/trailing constraints from the collection item view, but then the items are not flush together. I can't have gaps between the items and I can't the items overlapping each other.
2) I've tried removing the aspect ratio and the items resize correctly but don't maintain their aspect ratio.
3) I've also tried setting an aspect ratio on the collection view width such that it equals the height of the collection times the number of items times the aspect ratio, but wasn't able to get it to work correctly (and it seems kind of hack-ish). I also tried a custom layout object but I ran into different errors.
3) I was considering, but didn't try, de-activtating the aspect ratio constraint when the drag starts, and re-acivating the constraint when the drag ends but wasn't sure if this would work (it seems kind of hack-ish).
// setting up the grid layout
NSCollectionViewGridLayout* layout = [[[NSCollectionViewGridLayout alloc] init] autorelease];
layout.minimumInteritemSpacing = 0.0;
layout.minimumLineSpacing = 0.0;
layout.margins = NSEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);
layout.maximumNumberOfRows = 1;
layout.maximumNumberOfColumns = 0;
layout.minimumItemSize = NSMakeSize(260.0, 160.0);
layout.maximumItemSize = NSZeroSize;
self.theCollectionView.collectionViewLayout = layout;
(not shown are the constraints in the collection view item xib file)
The desired result is to have:
a) User resizing a single row of collection view items by dragging a split view divider, and they maintain their aspect ratio while being resized.
b) Ideally, collection view items would be centered horizontally in collection view if the items don't scroll horizontally.

How can I make all panels resize equally when form is maximized

Currently when I maximize my form it resizes as it looks below.
This is due to the anchoring element stretching the two bottom panels on the left as well as causing a gap on the right since nothing is anchored right. I could fill the gap on the right by anchoring the right most panel however that would just cause it to be wider than all the other panels.
What I want is an equal resizing of the panels when the form is maximized as depicted below
How can this be achieved?
Use TableLayoutPanel:
Add TableLayoutPanel to the form and set Dock = Fill
Add 2 rows to the TableLayoutPanel (by default there is already two)
Row 1 - Height = 50%
Row 2 - Height = 50%
Add 4 columns to the TableLayoutPanel (by default there is already two)
Column 1 - Width = 25%
Column 2 - Width = 25%
Column 3 - Width = 25%
Column 4 - Width = 25%
Four panels on the left side put inside every cell of first and second columns and set Dock = Fill
Two panels on the left side put in the third and forth columns of the first row, set RowSpan = 2 and Dock = Fill

UITableViewCell nib with several constraint scenarios

I have a UITableViewCell nib that depending on the data it can show an image or not.
Below, the cell has 2 labels and at the right most the imageView. What I want to do is to remove the imageView (if no image is present on the data) and extend the Label all the way to the right.
Is there a way to have several constraint scenarios on the nib that I could activate/ deactivate?
Constraints on label1
leading, 2. center vertically in container, 3. fixed width
Constraints on label2
Leading space with label1, 2. Center vertically in Container
Constraints on imageview
Trailing space, 2. Top space, 3. Bottom space,
Width constraint : width <= 50 (When there is no image then width will automatically get zero),
Horizontal space between
label2 and imageview = 0 (priority = 250)
See the below GIF:

How do I control the direction in which my UILabel Expands?

I have several Buttons each with three UILabels alongside them, half of these buttons two labels to the left as shown below. Each label has a number within it between 1 and 3 digits and will expand (using the UIView method 'sizeToFit') to fit this number. However when the labels are on the left the view overlaps the button when it expands. How can I fix this?

Controlling XAML grid structire using VisualStateManager

I am writing a WinRT app and need to change its layout in a snapped view. In a regular view details are displayed in grid of a following structure:
MainGrid: contains 2 rows, 2 columns (let's call them M11, M12, M21, M22)
DetailGrid: occupies rightmost column and upper row of MainGrid, contains 1 row, 2 columns of equal, so the layout looks like this:
M12 contains D1 and D2 layered horizontally
In a snapped view I want DetailGrid to be redefined so it has a single column and 2 rows:
M12 contains D1 and D2 layered vertically
If I didn't care about column width, I could use StackPanel instead of Grid to display details and simply change StackPanel orientation in a snapped mode from Horizontal to Vertical. But D1 and D2 must use all available space in a standard mode and have equal size, therefore I control them via Grid ColumnDefinition. But grid definition is not something that is easily controlled using VisualStateManager.
What do you think would be the best way to manage such layout?
Thanks in advance
Grid definitions are hard to control but I've found changing Grid.RowSpan or Grid.RowColumn span on the controls within the grid should be able to do what you need in snap view