I am attempting to render a multiline text block in SwiftUI using the Text component. I'm passing it a string that contains newlines and tabs, however whenever it is rendered, all of these special characters appear to be removed from text and the content is all rendered in a straight line. Does anyone have any ideas how to convince SwiftUI to actually let this be multiple lines?
let s = "{\n\t\"hey\":\"there\"\n\n\n}"
Text(.init("`\(s)`"))
The above code renders as:
From the docs modify your code accordingly.
Ex.
Text(“In SwiftUI Multiline text is great. \n Right?”)
.lineLimit(nil)
this works for me:
let s = "{\n\t\"hey\":\"there\"\n\n\n}"
Text("`\(s)`")
or
Text("\(s)")
or
Text(s)
Related
I am trying to display text over time using altair (vega-lite), which works fine using a layered chart, where one is created using the alt.Chart().mark_text() function to display the text.
The text though is multiple phrases and should be wrapped (with line breaks). How can this be done?
(I do not want to use fixed line breaks, e.g. \n, at distinct positions since the text wrapping should work with zooming too)
Not exactly what you want, but you can specify a character on which to break to a new line. When zooming, the text stays the same size, so it should always fit the view.
For example making a new line for every word:
.mark_text(lineBreak=' ')
I have a text field which I need to style for example with bold or italics parts.
I tried overridding the TextEditingController's buildTextSpan and formatting the text using annotation ranges with custom styles but the edge cases were too much and I really couldn't get it to work.
So, thought about using a formatter where before every change in format I'll add a custom character, like this:
This text is |bBOLD and this is |iITALICS. Would get me this:
This text is BOLD and this is ITALICS. So I override the buildTextSpan to build the TextSpan from a parse function where I split the text by the special characters and check the initial letter of each text for formatting info.
This works well except for the fact that when I press the right arrow to go the next character after the "This text is ", the cursor will stay fixed as it thinks there are two characters but being only for formatting, they aren't there on the render.
Is there any way I could tell the textfield to ignore certain characters when selecting, moving selection or typing?
I think this would work!
static const kCharToBEIgnored = 0x2C;
// Here 0x2C means ',' comma
// For complete list visit https://api.flutter.dev/flutter/charcode/charcode-library.html
String get text {
return String.fromCharCodes(
_value.text.codeUnits.where((ch) => ch != kCharToBEIgnored),
);
}
I'm working on an app that displays lyrics for several hymns in my native language.
Each line of the hymn is an individual Text Widget. I want the text to indent if it got softWrapped if user increases the font size to indicate that its not the next line. How can I achieve this effect?
Adding one or more tab escape characters "\t" to your strings may do the trick for you:
Text("\t this is a text string that will have an indentation",),
We have a SAPUI5 timeline control, where we are showing the comments coming from server.
The issue is, if the comments contain a newline \n, then the Timeline control is not able to display the text in newline. Instead, it introduces space wherever \n is present.
We have tried formatting \n to unicode character also but that also didn't worked. Timeline control aggregates TimelineItem.
The control we are using is: https://ui5.sap.com/#/api/sap.suite.ui.commons.TimelineItem
Code snippet can be found at:
https://jsbin.com/kuluyehilu/edit?html,output
I inspected your example and came up with the following solution.
Since the text is embedded in a <span>, all unnecessary whitespace will be trimmed. What you can do is telling the span (via CSS) that it should display the whitespace anyway.
If you don't have a CSS file in your project yet, create one. Then add the following lines
div.sapSuiteUiCommonsTimelineItemShellBody>span {
white-space: pre;
}
This should do the trick.
JSBin: https://jsbin.com/feladeneso/1/edit?html,output
If you inspect the rendered element, you will see it actually put in the break:
<span id="__item0-realtext">x
y</span>
...but did not convert it to a <br/> tag. You cannot add the tag yourself since it will be escaped, either. Maybe you can try to override the renderer, and convert any line breaks to html breaks
I'm almost left with no time but facing a problem with DataDynamics.ActiveReports.
I have to replace some text for 500 reports so automating the task through code at run time.
The major problem I'm facing is on replacing text the original bold wont changes to normal font. center justified text will be left justified also Arial Narrow text changes to Arial.
Is there any way to replace text without disturbing the original format.
Here is the piece of code:
var textBox = (DataDynamics.ActiveReports.RichTextBox)reportSection.Controls[controlIdx];
if (textBox.Text.Contains("Babu"))
{
MessageBox.Show(textBox.Text);
var modifiedtext = (DataDynamics.ActiveReports.RichTextBox)reportSection.Controls[controlIdx];
modifiedtext.Text = modifiedtext.Text.Replace("Babu", "Mannu");
MessageBox.Show(modifiedtext.Text);
}
The modified report has a format different than the original. How to fix this issue??
its richtext, not plain text.
every rich text has a formatting associated with it.
try editing the original rtf that you are loading into the rtb control. This is what I would recommend.
Or, another approach could be to use richtextbox.rtf.replac instead of richtextbox.text.
At what time of the report processing are you doing this?