Text isn't positioned precisely enough - konvajs

If Konva.Text align is set to right or verticalAlign to middle or bottom it's not being positioned well enough and always have some offset from right or/and bottom. Are there any ways to fix that?

Related

How to specify a constraint for a UILabel to remain centered beneath each segment of a UISegmentedControl?

In my app for iOS 8, I have a UISegmentedControl that stretches to fit the width of the device's screen. So on an iPad it's more pixels wide than it is on an iPhone 6+, which is more pixels wide than the iPhone 6, etc.
Centered just beneath each segment of the UISegmentedControl, I have a UILabel. So there are 5 segments and 5 UILabels. Each UILabel has a fixed width (fixed by constraint). However if the display size increases they become uncentered.
How in Interface Builder can I specify a constraint that will force each UILabel to become centered beneath each segment? I would be happy if I could just get the elements to remain proportionally spaced with each other as the display size scales, but I can't figure out how to do that, either.
All I can seemingly do is to center the middle UILabel directly under the middle segment by specifying a Center X Alignment between that and the UISegmentedControl.
I specified a Horizontal Space constraint between all the UILabels, and between the outer UILabels and the edges of the view, and set all these to "greater than or equals". They all have the same priority, but strangely, they don't all scale proportionally to each other.
The resulting problem is that the amount of Horizontal Space between each of the UILabels does not scale smoothly as the width of the device's screen increases. If I align everything to be in the proper positions on the iPhone 5S width of screen, then on the iPad their alignment is all wonky, and only the middle one lines up with its segment. The rest of them are all off center.
It appears that there is no way to specify a percentage of the over-all display width as a constraint -- you can only specify things in terms of pixels. Really?!?!
Clearly I could make the width of the objects to be flexible, but because they are text labels with right-aligned text, that screws everything up.
Surely I'm missing something here... since the point of Auto Layout is to make your interface scale according to the screen size, surely there is a way to specify a constraint as a percentage of any given view or subview... surely!!! But how? I've read the documentation and I cannot, for the life of me, figure it out.
BTW I did see that in the past, people have used crude hacks like spacer views or multiple sets of constraints, but surely those are outdated answers, and I'm just overlooking something extraordinarily obvious... right?
You can do this by making the centerX constraint of your labels equal to the superview.trailing times 0.1, 0.3, 0.5, 0.7, and 0.9 with constants of 0. To make these constraints, add your 5 labels to the view. Give the left most one a vertical spacing constraint to the segmented control. Select all 5 labels and give give them a "vertical centers" alignment constraint. Now control-drag from each label to the right side of the screen, and select the "Trailing space to container margin" constraint. Edit each one of these trailing constraints to look like this (except for the multiplier that needs to be given the values I mentioned above):
You'll have to reverse the first and second item (which you do from the pull down on the first item), change the Label.trailing to Label.Center X, and uncheck the "relative to margin" box, then correct the constant and multiplier values.
This approach will only work if the segmented control stretches all the way across the screen with no padding to the edges. If you want padding to the edges, then you need to use a completely different approach. You would need to create 5 UIViews below your segmented control -- align the left edge of the left-most one to the left edge of the segmented control. Align the right edge of the right-most one to the right edge of the segmented control. Give the 5 views equal width, and 0 length horizontal spacing constraint from each to its neighbor. This will give you 5 views that mimic the segmented control in width, with each view being the same width as one of the segments (assuming all the segments are the same width -- if that's not the case, you're screwed). Then you only need to add your labels as subviews of these 5 views, and give them centerX and centerY constraints.

VFL that makes two buttons aligns to two edges

I want to make two buttons that aligns to left edge and right edge, but following VFL failed.
#"H:|[leftToolbar(60)]-[rightToolbar(60)]|"
The result looks like they all pushed to the left, the second right toolbar was not pushed to the right.
What did I miss here?
#"H:|[leftToolbar(60)]-[rightToolbar(60)]|" says this ...
leftToolbar width should be (60)
rightToolbar width should be (60)
space between leftToolbar right edge and rightToolbar left edge should be standard (20, 8, ... depends on situation) (...]-[...)
leftToobar left edge should be aligned with superviews left edge (|[...)
rightToolbar right edge should be aligned with superviews right edge (...]|)
If standard space is 20 for example and your superview width is not 60+20+60=140 I would expect random results.
You can split it in two VFLs ...
#"H:|[leftToolbar(60)]"
#"H:[rightToolbar(60)]|"
... which says 60 for both buttons, one aligned to the left, another aligned to the right and I don't care whats between them and even if they overlap or not in case of small views.
Or do what Praveen recommends, but play with priorities (#...) to say what's more important for you. For example item width, or spacing between them, ...
Try this #"H:|[leftToolbar(==rightToolbar)]-[rightToolbar(==60)]|"

How do I solve this Auto Layout "puzzle" with constraints?

On the left is the normal state of the layout. On the right is the expanded state of the layout.
My problem is that I can't figure out how to keep the pink boxes centered within their cells, and the green lines connected between the pink boxes as the layout grows in any direction.
The AutoSizing.xib with just these two views can be found here: https://dl.dropboxusercontent.com/u/6979623/AutoSizing.xib
There are two approaches to keeping the pink boxes centered within the four quadrants of the super view:
You can add four invisible views that even split up the four quadrants of this main view (using constraints to pin them to their respective corners and another set of constraints to make them equal widths and heights). If I were going to represent that in VFL (just because it's a concise way of representing all of those constraints), it might be something like:
H:|[quadrant1][quadrant2(==quadrant1)]|
H:|[quadrant3(==quadrant1)][quadrant4(==quadrant1)]|
V:|[quadrant1][quadrant3(==quadrant1)]|
V:|[quadrant2(==quadrant1)][quadrant4(==quadrant1)]|
You can then center the pink views in the center of each of those four quadrant views.
You can add center constraints that employ multipliers to offset these pink squares within their shared superview. Interface Builder has only recently gotten multiplier support and it's not super solid, in my opinion, so when I want to use multipliers, I often fall back to adding those programmatically.
Once you have the pink boxes laid out correctly, then the green lines between them are simply fixed spacing leading/trailing or top/bottom for horizontal or vertical lines, respectively. Combine that with fixed width and center alignment and you're done. Bottom line, take care of the placement of the pink boxes, as discussed above, and then the creation of the green lines becomes pretty easy.

Layout UILabels with baseline offset

I have a view with labels stacked vertically. The design specification for the view give a vertical offset from the baseline of the text in the top label to the text in the bottom label.
However when I code for this, the size of the top UILabel will always be big enough to accomodate the descender of the top label. So I can only program the offset from the descender, not from the baseline. In the attached picture, red offset is what I want to code for, but I can only code for the green offset. Is there any way that I can get the baseline offset correct either in the xib or through code? I do not want to do this by trial and error, as that would result in the programmed offset not matching the specs.
You can do it, but easier to show you in a screen shot than to explain it:
Change "30" to whatever your specified distance is.

Right Align Gap in sIFR

When I right align there is what appears to be like a 3-5 pixel padding on the right. But when it is left aligned it is perfectly lined up with the content. Any help would be appreciated.
Try using a negative value for tuneWidth to remove the extra space.

Resources