Text formatting for a string - apache-flex

Can I set the font size for string? I want to do text formatting for string, Is it possible in flex?

You can use TextField/UITextField to display formatted text. In both classes you have two options:
You can use setTextFormat() method to format text
You can use htmlText property to display HTML text. These classes don't support all HTML tags. Supported HTML tags are listed here.

If all you need to do is change the font, you can use the StyleableTextField class or the Label and set the . She can set the fontSize style of either class to globally change the font size.

No,
you need to set the font size of label or any text other Text control that you use to show string value.
var str:String = 'This is sample text';
//set in any method
lbl.text = str;
lbl.setStyle('fontSize', 20);
enjoy.

Related

JavaFX Text in TextFlow ignores StyleClass?

I try to use a javafx TextFlow to view some styled text. The following code does not do any text styling.
public Node createText(String t,String cls){
Text ret = new Text(t);
ret.getStyleClass().add(cls);
return ret;
}
When I replace Text with Label it works properly, but things like \n obviously do not work anymore. How can I use the Text class with css classes?
EDIT: As requested a short example of my default.css
.defaultElementAttr{
-fx-text-fill:#48a711;
}
-fx-text-fill is a CSS property of Label but it is not a CSS property of Text.
If you want to change the color of a Text object with CSS, use the -fx-fill property:
.defaultElementAttr {
-fx-fill:#48a711;
}

Spritebuilder CCTextField how to set placeholder and color?

I want to ask how to set CCTextField placeholder and color.
I know it is easy to create a text field on spritebuilder, but it cannot set the text color and placeholder like UITextField.
yourTextField.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:#"Placeholder String" attributes:#{NSForegroundColorAttributeName: [UIColor grayColor]}];
Same thing if you have to use the text too. Use the property .attributedText
When I had this problem I had to change a Cocos2d file:
cocos2d-ui/Platform/iOS/CCPlatformTextFieldIOS.m
- (id)nativeTextField
{
return _textField;
}
I would recommend just trying to use attributed string before changing cocos2d files. I'm using cocos2d v3 and xcode 6.1.1

Convert HTML Email into plain text, is it possible to add colour / style

We currently have a bad situation where I need to change HTML Body content from a CMS and convert it to plain text so it can go into the body of an emailto.
private static string StripHtmlToAscii(string mergeEmailBody)
{
var asciiEmailBody = mergeEmailBody;
asciiEmailBody = asciiEmailBody.Replace("<br />", "%0D%0A").Replace("<br/>", "%0D%0A").Replace("+", "%20").Replace(" ", "%20").Replace("<p>", "").Replace("</p>", "%0D%0A%0D%0A").Replace("<br>", "%0D%0A");
return asciiEmailBody;
}
See above..
I am wondering is it possible to add style like bold or colour to a plain text email ?
No, plain text is plain text, it will only accept text. The only way you can add colour is by sending an HTML email

Flex 3 Multicolored Text in DataGrid Cell

I am having an issue with styling individual cells in a DataGrid. I want to go through the text in a DataGrid cell and only color a specific portion of the text.
When a User uses a search filter, we want to color and bold the text in the cell that matches the search phrase. For example, the User filters a column of job titles with the search phrase "Adjust" and one of the cell values is "Claim Adjusters", we want "Claim " and "ers" at the end to be black font color and the "Adjust" to be another color (let's say red).
I noticed that if the String passed to the DataGrid was of the form:
value.substring(0,start) + "(b)" + value.substring(start,finish) + "(/b)" + value.substring(finish);
With "<>" rather than "()", the text between the bold tags gets displayed with a bold font, but it does not work with (font color=\"red\") ... (/font).
Any suggestions on how I can get the search text to color here as well as bold?
Only hexadecimal color (#FFFFFF) values are supported.
A simple alternative with lots of flexibility is to make your itemRendrer support html formatting:
public class HtmlItemRenderer extends DataGridItemRenderer {
override public function validateProperties():void {
super.validateProperties();
if (text.indexOf('<') > -1) {
htmlText = text;
}
}
}
The conditional doesn't need to be very strict, it will still save some cycles for most cells that contain no markup.

calculating Spark TextArea width

I am treating a spark TextArea as text input(by setting heightInLines="1"). The TextArea is part of an mxml component and I want to resize the component when the text is changed.
I haven't been able to use textArea.measureaText(textArea.text) to get line metrics and use it. I get this error "Parameter antiAliasType must be non-null."
Is there any way to get the width of a TextArea which it is going to consume at runtime for a particular string or a particular TextFlow?
A little ugly but works for me:
var uiText:UItextField = new UITextField();
// if you have custom text style on the TextArea then set it the same of this uitextfield
uiText.setTextFormat("bla bla bla");
uiText.text = "This is the text that I want the size for";
var textW:Number = uiText.textWidth;
var textH:Number = uiText.textHeight;
// then we need to consider also the border of the text area and the paddings
// try read the padding values and border sizes using getStyle(...)
myTextArea.width = textW+2*borderW+paddingL+paddingR;
myTextArea.height = textH+2*borderH+paddingT+paddingB;
That should be all

Resources