Evenly aligning things in IB - iphone

I have ten labels on a view positioned vertically. I need to evenly space them. Does IB have any type of setting that will do this?

If you select individual labels and drag them around the view, they should "snap" to certain guides around the interface. If you drag an element close to another element it should snap to about 8 pixels away, and that's the standard spacing between elements on the iPhone.
If you want more precise control, you can select an element and use the arrow keys to move it around one pixel at a time.
You can also use the Align Horizontally/Vertically in Container menu items from the Layout menu.

Do the math and then type in the X,Y coordinates. Unfortunately, I think that is the easiest way.

If you are OK using Apple's guideline spacing, dragging one label near another will generate a dashed line at a certain point. Do this for each label below the next, and they will be evenly spaced.

Related

Unity3d. UI elements snapping/anchoring

I have canvas with vertical layout and 2 elements within (in fact it's element with only recttransform on it, let's call it container). So these 2 containers take a half of the screen by height and stretched by width, ok. How can I place an text element in above container and snap it to the bottom of this container? I tried press bottom button in recttransform widget (also with shift and alt) and it seems it doesn't affect my transform at all
P.s. May be I can use some free plugin instead of default unity components of UI layout?
There are different ways of placing your UI elements
Simply drag and drop it to the bottom where you want it
Use the anchor widget to set the anchoring to bottom with horizontal stretch and hold shift to also set pivot. Then set Pos Y to 0. Set Left and Right to 0.
Assuming you also want other elements in your containers, place a Vertical Layout Group on each container and make sure that your text element is the last child of the container in the hierarchy.
I would also advise you to seek out tutorials on Unity UI anchoring, positioning, scaling, and layout. You need a deeper understanding of how these things interact than you are likely to get from Stack Overflow. Otherwise you will suddenly find that your UI behaves in unexpected ways when rearranged or displayed on a different aspect ratio.
It's fairly easy with Unity UI system. You just need to get used to it. Here are simple steps to accomplish what you want:
Create Text element as a child of that container.
Select your newly created element and edit its RectTransform component values:
2.1. Set both Y axis anchors (min and max) to 0.
2.2. Set pivot value to 0 as well.
2.3. Set Pos Y value to 0 as well.
Now your Text element is anchored at the bottom of the container and its position (and height) is measured from the bottom of the Text element itself.

Auto Layout issues

I am trying to get a layout working where I have 9 squares set 3 x 3 and on all device sizes, they are square.
I have tried endless ideas to make it work but can't seem to get it to stay squares on all devices.
I attached below, a picture showing the results and current constraints on the top left corner square.
Any help would be awesome!
The best approach would be use the stackView. The advantage will be you do not have to deal with the much constraints. So select the first rows three view horizontally then click on the Embed in Stack button whose axis should be horizontal inside your storyboard. Follow the same for second and third rows. Also inside stackview you can mention the spacing you want.
So now you have three stackView for all the three rows. After that select all three stackView then click on the Embed in Stack button and whose axis should be vertical and you can mention the spacing you want.
So advantage of doing that is you do not have to worry about the constraints. Finally you only have to apply the constraint on your main stackView which hold all your child stackView
While I totally agree that UIStackView is a great option, you can also add Aspect Ratio constraints (with a Multiplier of 1) to your squares and ensure that they remain squared (as nothing about your current layout demands that your views should be squares).
If you want your 9 squares to remain in the center of the superview, I recommend adding them to an invisible intermediate view and center that within the superview.

Can't get vertical layout group with scrolling working

I've got a panel which sits above my canvas and slides out upon clicking a button. I want to populate this panel with several objects (the number will be determined at runtime). Since the number of objects can exceed the number that would reasonably fit on a single row of the panel, I'd like to be able to scroll down with the mouse to new rows where the remaining objects have been populated.
To achieve this I've put a Scroll Rect and a Mask on the panel, created a child Image with a Vertical Layout Group to hold a series of child panels representing the rows that would hold the objects, and set the Image as the Content of the Scroll Rect.
The issue is that when I try to make one of the row panels a child of the Image object by dragging it to the Image in the Hierarchy, the anchors for the panel coalesce to a single point (the top left of the Image since it is set to Upper Left alignment) and when I try to manually drag the anchors to the appropriate position a box with a red X in it appears and expands in a manner that doesn't seem to correspond to the direction of the mouse.
Is this the right approach, and if so, how can I get this to work?
Thanks!

Vertical Align Crystal Report Text Filed

I have a scenario in which my reports fields doesn't look like centered Vertically,
Below is the screen Short of the output.
As it can bee seen from output that data with a bigger font is clearly seen centered vertically, but the data pointed with lines is left-top justified, i want that to be left-centered.
For vertical alignment I did this .
and code behind formula is:
if {NewReport;1.TireLevel} = 1
then
crCenteredHorizontally
else
crLeftAligned
The Editor Screen.
Sadly, Crystal Reports doesn't support vertical alignment in the same way it supports horizontal.
It's possible to use labels on the vertical ruler and enforce Snap to Grid, but that might not work within a table. Or you can add line breaks, blank rows, or plain white objects to push things into position. But there's no easy way to enforce a vertical center.
In your particular case, I would actually make two seperate fields: One for large text and one for small text. Layer them on top of each other and reuse your current formula to alternate their suppression. This way you can move the smaller text vertically down without undoing the vertical alignment on the large text field.

iOS: Aligning two UILabels (left/right) and connecting with dots?

The above image was taken from an Android app. I am looking to do the same thing on iOS. I know how to do it using a background image for the dots, but it doesn't look like the Android developer used an image for the dots. Anyone know how this can be done?
I've found the way to do it with content hugging/compression resistance.
Here is the interface builder solution:
Left label has a phrase and lots of dots with line breaking = truncate tail. Content hugging/compression resistance do the rest of job.
I think you can do this without any code. Just use two labels with their baselines aligned, and with a horizontal spacing constraint of 0. The left label would have its text left aligned with say 10 dots added to the end of the string, and the line break mode set to "clips". The right label would also be left aligned, so its text would always be right up against the dots.
After Edit: I couldn't get this to work in IB. It may be possible in code using constraints, but I haven't tried that. It seems like you should be able to do it with 3 labels, with the two outside ones pinned to the edges of the view, and a flexible label in the middle whose text would be dots.
You can use NSAttributedString to format in that way.
Use two colors in two ranges, even bold font for 2nd part.
And calculate the total width (length of your text) and fill dots (.) in between those.
An idea to fill dots:
lets say you have 30 characters space.
str1 contains 10, str2 contains 6, then use 30-(10+6) then in a loop
for(30-(10+6) times) {
[mainString appendString:#"."]
}