如何在 Flex 3 中使用 htmlText 作为单选按钮标签单选、按钮、标签、如何在

2023-09-06 19:40:12 作者:ポ

我需要在 Flex 3 中为单选按钮显示几个粗体字.如下所示:

I need to show few words in bold for radio buttons in Flex 3. something like the following:

选项 1:你好 世界.

选项 2:你好世界.

我看到单选按钮的标签没有 htmlText 属性.有人对完成此要求有什么建议吗?

I see that there is no htmlText property for label of Radio Button. Anyone has any suggestions in accomplishing this requirement?

谢谢

安吉

推荐答案

@Timofei Davydik

@Timofei Davydik

您可以通过扩展 RadioButton 并覆盖 updateDisplayList 函数在 RadioButton 标签中包含 HTML 文本.您需要在此函数中将 textField 的 htmlText 属性更改为标签的值.

You can include HTML Text inside RadioButton labels by extending RadioButton and overriding the updateDisplayList function. You need to change htmlText propert of textField to label's value inside this function.

这里是 HTMLRadioButton 组件

Here is the HTMLRadioButton Component

package components
{

import mx.controls.RadioButton;

public class HTMLRadioButton extends RadioButton
{
  public function HTMLRadioButton()
  {
    super();
  }

   override protected function updateDisplayList(unscaledWidth:Number,
                                              unscaledHeight:Number):void
   {
        super.updateDisplayList(unscaledWidth, unscaledHeight);
        textField.htmlText = label;

   }
}
}

更新:

如果您需要 RadioButton 标签中的多行 HTML,那么您需要扩展此 组件同上.

If you need multiline HTML in RadioButton label, then you need to extend this component in the same way as above.