改变Button控件的文件对齐方式。
Button控件的
示例:
代码:
或者通过setStyle()方式实现:
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>
<!-- 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" />
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();" />
<![CDATA[
private function init():void {
button.setStyle("textAlign", "right");
}
]]>
</mx:Script>
<mx:Button id="button"
label="Button"
width="200"
initialize="init();" />