Flex中如何通过cornerRadius样式设置PopUpButton边角圆滑程度的例子

By Minidxer | March 15, 2009

接下来的例子演示了Flex中如何通过cornerRadius样式,设置PopUpButton边角圆滑程度。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="top"
  5.         backgroundColor="white">
  6.  
  7.     <mx:Style>
  8.         PopUpButton {
  9.             popUpStyleName: myCustomPopUpStyleName;
  10.         }
  11.  
  12.         .myCustomPopUpStyleName {
  13.             fontWeight: normal;
  14.             textAlign: left;
  15.             leftIconGap: 0;
  16.         }
  17.     </mx:Style>
  18.  
  19.     <mx:Script>
  20.         <![CDATA[
  21.             import mx.controls.Menu;
  22.  
  23.             private function init():void {
  24.                 var menu:Menu = new Menu();
  25.                 menu.dataProvider = arr;
  26.                 popUpButton.popUp = menu;
  27.             }
  28.  
  29.             private function resizePopUp():void {
  30.                 popUpButton.popUp.width = popUpButton.width;
  31.             }
  32.         ]]>
  33.     </mx:Script>
  34.  
  35.     <mx:Array id="arr">
  36.         <mx:Object label="Alert" />
  37.         <mx:Object label="Button" />
  38.         <mx:Object label="ButtonBar" />
  39.         <mx:Object type="separator" />
  40.         <mx:Object label="CheckBox" />
  41.         <mx:Object label="ColorPicker" />
  42.         <mx:Object label="ComboBox" />
  43.     </mx:Array>
  44.  
  45.     <mx:ApplicationControlBar dock="true">
  46.         <mx:Form styleName="plain">
  47.             <mx:FormItem label="cornerRadius:">
  48.                 <mx:HSlider id="slider"
  49.                         minimum="0"
  50.                         maximum="{popUpButton.height / 2}"
  51.                         value="0"
  52.                         liveDragging="true"
  53.                         snapInterval="1"
  54.                         tickInterval="1" />
  55.             </mx:FormItem>
  56.         </mx:Form>
  57.     </mx:ApplicationControlBar>
  58.  
  59.     <mx:PopUpButton id="popUpButton"
  60.             label="Please select an item..."
  61.             cornerRadius="{slider.value}"
  62.             arrowButtonWidth="{popUpButton.height}"
  63.             openAlways="true"
  64.             initialize="init();"
  65.             creationComplete="resizePopUp();" />
  66.  
  67. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: PopUpButton | No Comments » | 473 views Tags: ,

Search Posts