How to block align text in SwiftUI Text View? - swift

There is left, center and middle aligned text.
Yet no block alignment like in other Word Processors.
How can one align text in a view using block format?

For example, if you put text in a label, you can justify the text contained in this way:
label.textAlignment = NSTextAlignment.Justified

Related

VBA Word o set textbox text/paragraph vertical alignment to "center"

I have created a textbox in Word and can set various properties for it, such as position, text, text style, text horizontal alignment (left/right/center), color, and so on.
But I cannot find any settings to set the vertical alignment of text in the box to Top/Middle/Bottom. There's a button for vertical alignment on the ribbon to set that property, but I can't find it through the object inspector, through Intellisense, or through searching the net. I tried recording a macro, but the only line that showed up in the macro was the VBA line to select the textbox. Nothing else. :-(
The ribbon button is beside the "set text direction" option, but I couldn't find VBA for that setting either. I also tried the Textframe2 property, but saw nothing in there for vertical alignment.
Here's the code that sets the horizontal alignment of text. Also, I included the enum that I think I need to use. But I can't find the property to accept a value from the enum.
tbox.TextFrame.TextRange.ParagraphFormat.Alignment = wdAlignParagraphRight
WdVerticalAlignment enumeration (Word):
Name Value Description
wdAlignVerticalBottom 3 Bottom vertical alignment.
wdAlignVerticalCenter 1 Center vertical alignment.
wdAlignVerticalJustify 2 Justified vertical alignment.
wdAlignVerticalTop 0 Top vertical alignment.
Does anyone know the syntax for the property that I need to set to vertically align text inside a textbox shape? Thank you
The property is TextFrame.VerticalAnchor that uses the enumeration MsoVerticalAnchor
For example:
ActiveDocument.Shapes(1).TextFrame.VerticalAnchor = msoAnchorMiddle
(The enumeration mentioned in the question is for page layout.)

Get lines of a UI text in Unity3D

I use the following code to get everyline of a text that I have in Text. but the code does not return the lines that are showing in the game, it returns what I have entered in inspector.
myText = GetComponent<Text>();
string[] lines = myText.text.Split('\n');
try{print(lines[0]);}catch{}
try{print(lines[1]);}catch{}
//real output :
//New Text
//What I expect:
//New
//Text
There is a picture :
Screen Shot
How can I get lines that are in the game window?
This is my first post, so excuse any mistakes
The text is displayed as two lines because of the the Text.horizontalOverflow property of the Text component is set to Wrap, but that not means it has been changed to two lines like "New \nText". It is still "New Text".
If you set horizontalOverflow to Wrap, Text will word-wrap when reaching the horizontal boundary. So the output becomes two lines in your case.
You need to set it to Overflow so the text can exceed the horizontal boundary. Then the text will not be influenced by the border of the text GameObject.
Is the same text, the problem is that the width of the RectTransform of the Text Object is too small, increase the width or decrease the text size.

Text in textview is not vertically centered

I'm trying to create a text view which height follows number of line in it. I've worked on constraint but here I've a curious issue :
At the beginning all is centered as I want
When there is a break, text is not vertically centered anymore and goes in top left corner
When you delete characters and then come back to previous line, the text is yet vertically centered
Here is the code
func textViewDidChange(textView: UITextView) { //Handle the text changes here
if(textView.text != ""){
self.animateSendButton(true)
}else{
self.animateSendButton(false)
}//the textView parameter is the textView where text was changed
heightTextfieldConstraint.constant = self.textField.contentSize.height + 2
textField.contentInset.top = 1
}
I don't understand why there are these 3 different cases, do you have any idea to solve it ?
You can try and add an inset to the top, bot, left and right, that should keep the text centered even after a second line appears.
textView.textContainerInset = UIEdgeInsetsMake(5, 5, 5, 5)
You might be better off keeping the text view itself vertically centered while ensuring that the text view is always sized to fit the content. You can do this with Auto Layout.
Set the text view to be vertically centered in its container and also add a height constraint to the text view with a low constant value (about the height of 1 line of text). Then set the text view's Content Compression Resistant Priority to a value that is higher than the text view's height constraint (see screenshots).
I've done it in "Main.storyboard" of this demo project of mine if you want to see a working example:
https://github.com/patricklynch/Walkthrough
Perhaps you could call view.layoutIfNeeded() after text has been entered.

nstableview how to fit text

The problem is to fit text into cell. With cell.textfield.sizetofit() and layouts I can create text on more than 1 line, but visible is only one
if I make text size small I can see second line but cut by half

How to make UILabel to fill available space with autolayout?

I have a text label which can contain text in length from a few words to a few paragraphs. I want it to behave something like a <p> does in HTML. It is set up like this:
It is attached to the left ("Equals 18 pixels"), to the top ("Equals 31 pixels") and to the right ("Greater than or Equal").
The result looks like this:
You can see, that autolayout is right, all the constraints are fulfilled, but it is not what I wanted. It somehow misses an equalation which tells the value label to fill the maximum space horizontally it can fill. How can I set this up using Storyboards?
This should to the trick:
Remove the right constraint.
Drag the UILabel to the desired width.
Add a new constraint by selecting the UILabel and use the Editor > Pin > Trailing Space to Superview menu option.
Select your UILabel and then in Editor menu select Size to Fit content
Also remove the right constraint ("Greater than or Equal").
Doing this, your label will stretch horizontally to fit its content.
This will solve your problem.. :)