iWatch: WKInterfaceLabel is it possible to stop text from being cut off with "..." at the end of a label? - swift

The text in my WKInterfaceLabel is way too long and causes the text to be cut off with dots at the end. I know for UILabel for iOS you can easily resolve this issue by enabling clip mode. I don't believe there is any way for me to resolve this for watchkit. This is going to force me to use an Image if I can't prevent the text from being cut off. Any tips or suggestions is appreciated.

You have a couple options depending on how you want the view to respond. In your interface story board select your label and open the attributes inspector.
Your first option is to change the font to a smaller size. This is more for a static label that you want to style and leave set.
Your second option is to adjust the min scale value, changing this will automatically shrink the text to fit the window up to the value provided. For example if your font size is 12pt and you set the scale to .5, the font will shrink up to 6pt before appending the ellipsis (...).
Your third option is to set the number of lines to 0 (or a higher number). This will move the text down onto the next line.

Set the number of lines to 0 and ensure the label and any containing groups are set to fit content.

if you want your font size adjust according to label size follow this method
in WKInterfaceTable attribute inspector set min scale to 0
like in screen shoot
Result before Min scale = 0
Result after Min scale = 0
Note: your no of lines also set to 1

Related

Tableau: how to align text in dual axis-ed column labels

I am having trouble with label's text alignment. I used workaround to have rows coloured based on a value of certain row (featured in e.g. this tutorial); for example, if the Status is "Cancelled", it colours entire row red, otherwise it is green.
I created AGG(MAX(1)) columns for bar (with fixed range 0 to 1) and AGG(MAX(0)) columns for text (with fixed range 0 to 0), then paired them through dual axis.
However, I found out the text label is automatically aligned to the centre. I looked into text label options and set my alignment to the left (in both Edit Label window and Alignment setting) but it had no effect whatsoever. I changed Format... settings for column but once again, it had no effect.
I even tried changing fixed range on AGG(MAX(0)) columns or changing the zero in MAX(0) to some other number but this only moved centre-aligned text so it was of no use.
Here is a picture to illustrate my point:
I found out what was the issue and also arrived at better way to do it than the one I described in my question.
Here's the tutorial (using Tableau 2021.4):
Create a column MAX(-1). Right-click the column, go to Edit Axis..., set Range to fixed (start at -1, end at 0), delete the Title, and disable all Tick Marks (by setting them to 'None').
In Marks panel, set the Mark to 'Gantt Bar'.
Drop your condition for coloring (e.g. calculated field) on Color in Marks panel.
Create a calculated field MAX(1) and drop it on Size in Marks panel. This will fill out entire column width with a color bar. If needed, increase the bar width by moving the slider under Size to the right.
Drop the text value on Label in Marks panel. Now you should see text labels. If not, increase cell's height (Format > Cell Size > Taller or Ctrl+Up).
If you want a header (just like shown in my picture), create a column MAX(0), set its Range to fixed (start at 0, end at 0), disable all Tick Marks and change the Title.
Right-click the MAX(0) and tick 'Dual Axis'.
In case you'll encounter some challenges when formatting the end result, check formatting hierarchy (this tutorial may help).

What's the proper way to align a strechable Text and an image to two ends in Unity UI?

I have an UI element that has a Text and an Image as its children. It has a HorizontalLayoutGroup component that enables Control Child Size and Child Force Expand.
I want the Image has a fixed size, and Text has strechable size controlled by the HorizontalLayoutGroup. So when the Image is set to inactive, the Text fills the whole space and when the Image is active, the Text shrinks a little bit in order to give space to the Image. Right now this part works good.
My second goal is to align them to both ends: the Text in the left and the Image on the right with space in between. But changing Child Alignment can't achieve this.
I tried the following solution:
Add LayoutElement both to Image and Text. On Text, enable Flexible Width and set a a value, on Image, enable Min Width and set to a value. Manually adjust the two values until it seems right.
This solution seems to work, but I don't know why. Is anyone familiar with this?What's the recommended way to do it? Thanks!
I worked it out. On the LayoutElement, treat Preferred Width or Preferred Height as Max Width or Max Height. Enable them, set the value the same with min value. One the other objects that you want to stretch, enable Flexible values. Then all worked as we want.

Unity's text mesh pro input field caret is too wide and pushes text outside of textarea

I'm working on a mind map editor in which the user can draw boxes and write text in them. However, the TMPro input fields I'm using in those boxes have extra-wide caret when I type in them, and changing the fonts didn't solve the problem. Here are some images of the issue:
The caret is so wide that it can push the text inside out of the box:
I tried to lower the caret width in my script, but it's an int and has already been set to 1. Can you give me some possible reasons as to why this is happening?
I solved that problem by multiplying width+height of my inputfield by 100 and dividing its scale by 100.
Don't forget to increase the font size significantly.

UILabel: Get actual font size with adjustFontSizeToFit

I have two labels in my layout.
I want the font size to adjust to fit the label bounds.
I set to true the UILabel adjustFontSizeToFit.
Moreover a need the two labels to have the same font size. So I added an auto-layout constraint to make the labels have the same size.
The issue with it is the labels do not contain the same string. Sometimes the first is longer and vice-versa. The font I use doesn't have the same width for every character which will not allow me to use a space to fill to shorter string. (This solution looks a bit ugly to me).
I tried to get the label.font.size.pointSize after the label has been displayed but the value returned is always the one I set at the beginning (before being reduced to fit).
Does anyone have an idea on how I could achieve it ?

How can I prevent UITextfield font size from becoming smaller as you type

I have initialized a text box to have font size 16. Now I have noticed that as I type beyond the boundary of the text box, iPhone decreases the font size and then scrolls. Now If I delete everything from the text box and start typing, it starts with the small font and never becomes 16. Could you let me know how can I fix this? Can I initialize the font size at some method every time somebody starts typing?
Thanks.
In Interface Builder, if you select the text field, you can deselect the 'Adjust to Fit' checkbox in the TextField Attributes. The font should remain the same as you set it and will show an elipsis (50...) if the content exceeds the space available.
I think you have it setup so that text field adjust font size to fit the text inside.
Try not setting it or reset to what you require.
UITextField reference:
adjustsFontSizeToFitWidth
A Boolean
value indicating whether the font size
should be reduced in order to fit the
text string into the text field’s
bounding rectangle.
#property(nonatomic) BOOL adjustsFontSizeToFitWidth
Discussion
Normally, the text field’s content is
drawn with the font you specify in the
font property. If this property is set
to YES, however, and the contents in
the text property exceed the text
field’s bounding rectangle, the
receiver starts reducing the font size
until the string fits or the minimum
font size is reached. The text is
shrunk along the baseline.
The default value for this property is
NO. If you change it to YES, you
should also set an appropriate minimum
font size by modifying the
minimumFontSize property.