简体   繁体   English

Flex 4中的外观按钮标签

[英]Skinning Button Label in Flex 4

I am using a Skin for my buttons in Flex 4. The skinned buttons are displayed correctly. 我在Flex 4中为按钮使用皮肤。皮肤按钮正确显示。

Now I want the label of the buttons to respond as such: 现在,我希望按钮的标签响应如下:

  • Font Weight should be Bold when "RollOver" or "MouseOver" over the buttons. 当按钮上的“ RollOver”或“ MouseOver”时,字体粗细应为粗体。

I tried doing it in the mxml below by including the rollOver property to the Label on this button, but it doesnt seem to work. 我尝试通过在此按钮上包含Label的rollOver属性在下面的mxml中执行此操作,但是它似乎不起作用。

Am I doing it at the right place, that is in the Skin mxml file? 我是在正确的位置(即Skin mxml文件中)执行此操作吗? Or should I do it for each button in the Application itself? 还是应该对应用程序本身中的每个按钮执行此操作?

Skin Code: 皮肤代码:

<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Metadata>
        <![CDATA[ 
        [HostComponent("spark.components.Button")]
        ]]>
    </fx:Metadata>

    <fx:Script>
        <![CDATA[
            protected function labelDisplay_rollOverHandler(event:MouseEvent):void
            {
                FontWeight.BOLD;
                FontStyle.ITALIC;
            }
        ]]>
    </fx:Script>

    <s:states>
        <s:State name="up" />
        <s:State name="over" />
        <s:State name="down" />
        <s:State name="disabled" />
    </s:states>

    <s:BitmapImage includeIn="up" source="{getStyle('upSkin')}" width="100%" height="100%"/>

    <s:BitmapImage includeIn="over" source="{getStyle('overSkin')}" width="100%" height="100%"/>

    <s:BitmapImage includeIn="down" source="{getStyle('downSkin')}" width="100%" height="100%"/>

    <s:BitmapImage includeIn="disabled" source="{getStyle('disabledSkin')}" width="100%" height="100%"/>

    <s:Label id="labelDisplay" textAlign="right" maxDisplayedLines="1" horizontalCenter="1"
             verticalAlign="middle" verticalCenter="1" left="10" right="10" rollOver="labelDisplay_rollOverHandler(event)" />

</s:SparkSkin>

You can do this easily by changing the fontWeight style for the "over" state. 您可以通过将fontWeight样式更改为“ over”状态来轻松实现此目的。 You can do this in MXML by specifying the style followed by the state you want that style to be applied to, like so: 您可以通过在MXML中指定样式,然后指定要应用该样式的状态来完成此操作,如下所示:

<s:Label id="labelDisplay" fontWeight.over="bold" textAlign="right" maxDisplayedLines="1" horizontalCenter="1"
         verticalAlign="middle" verticalCenter="1" left="10" right="10" />

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM