小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

改变Button控件的文件对齐方式。

Button控件的textAlign 样式学习.三种方式实现。
示例:

代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/21/aligning-a-label-in-a-button-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white">

    
<mx:Script>
        
<![CDATA[
            import mx.events.ItemClickEvent;

            private function toggleButtonBar_itemClick(evt:ItemClickEvent):void {
                button.setStyle("textAlign", evt.item.label);
            }
        
]]>
    
</mx:Script>

    
<mx:Array id="arr">
        
<mx:Object label="left" />
        
<mx:Object label="center" />
        
<mx:Object label="right" />
    
</mx:Array>

    
<mx:ApplicationControlBar dock="true">
        
<mx:Form styleName="plain">
            
<mx:FormItem label="textAlign:">
                
<mx:ToggleButtonBar id="toggleButtonBar"
                        dataProvider
="{arr}"
                        selectedIndex
="1"
                        itemClick
="toggleButtonBar_itemClick(event);" />
            
</mx:FormItem>
        
</mx:Form>
    
</mx:ApplicationControlBar>

    
<mx:Button id="button"
            label
="Button"
            textAlign
="center"
            width
="200" />

</mx:Application>

你也可以在<style>标签中修改:

<mx:Style>
    Button {
        textAlign: right;
    }
</mx:Style>

<mx:Button id="button"
        label
="Button"
        width
="200" />

或者通过setStyle()方式实现:
<mx:Script>
    
<![CDATA[
        private function init():void {
            button.setStyle("textAlign", "right");
        }
    
]]>
</mx:Script>

<mx:Button id="button"
        label
="Button"
        width
="200"
        initialize
="init();" />

posted on 2008-05-21 15:54  『小小菜鸟』  阅读(707)  评论(0编辑  收藏  举报