如何在按钮标签中写入两行文本?

发布于 2024-10-20 22:48:29 字数 59 浏览 4 评论 0原文

对于按钮的“标签”字段,有没有办法在多行上显示文本?或者自动将文本“换行”成几行而不是剪切其中的一部分?

Is there a way, for a Button's "label" field, to display text over several lines? Or else to automatically "wrap" the text in several lines instead of cutting part of it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半暖夏伤 2024-10-27 22:48:29

这对于标准 mx:Button 来说是不可能的 - 您可以创建自己的自定义组件来扩展 Button 或查找其他已经创建了您需要的组件。

例如,flexlib 库包含一个 CanvasButton ,它可以帮助:
http://flexlib.googlecode.com/svn/trunk/docs /flexlib/controls/CanvasButton.html

或者,如果您喜欢自己动手并创建自己的自定义组件,这篇博文将向您展示如何:
http://www.forestandthetrees.com/2008/03/11/弹性多行按钮/

This isn't possible with the standard mx:Button - you can either create your own custom component to extend Button or look for others that have already created what you need.

For example the flexlib library contains a CanvasButton which would help:
http://flexlib.googlecode.com/svn/trunk/docs/flexlib/controls/CanvasButton.html

Or if you prefer to do it yourself and create your own custom component this blog post will show you how:
http://www.forestandthetrees.com/2008/03/11/flex-multiline-button/

羞稚 2024-10-27 22:48:29

假设您使用的是 Flex 4,您可以使用此组件:

WrappingButton.as

package 
{
  import flash.text.TextFieldAutoSize;
  import mx.controls.Button;

  public class WrappingButton extends Button
  {

    public function WrappingButton()
    {
      super();
    }

    override protected function createChildren():void
    {
      super.createChildren();

      textField.multiline = true;
      textField.wordWrap = true;
      textField.autoSize = TextFieldAutoSize.CENTER;
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
      super.updateDisplayList(unscaledWidth, unscaledHeight);
      textField.y = (this.height - textField.height) >> 1;

      height = textField.height + getStyle("paddingTop") + getStyle("paddingBottom");
      if (height < this.minHeight)
      {
        this.height = this.minHeight
      }
    }
  }
}

Assuming you're using Flex 4, you could use this component:

WrappingButton.as

package 
{
  import flash.text.TextFieldAutoSize;
  import mx.controls.Button;

  public class WrappingButton extends Button
  {

    public function WrappingButton()
    {
      super();
    }

    override protected function createChildren():void
    {
      super.createChildren();

      textField.multiline = true;
      textField.wordWrap = true;
      textField.autoSize = TextFieldAutoSize.CENTER;
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
      super.updateDisplayList(unscaledWidth, unscaledHeight);
      textField.y = (this.height - textField.height) >> 1;

      height = textField.height + getStyle("paddingTop") + getStyle("paddingBottom");
      if (height < this.minHeight)
      {
        this.height = this.minHeight
      }
    }
  }
}
佼人 2024-10-27 22:48:29

如果您使用的是 Flex 4,则使用 s:button,然后为其制作自定义皮肤。在皮肤里面你会看到

If you are using Flex 4 then use s:button and then make a custom Skin for it. Inside the Skin you will see

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文