---
title: "[转]NumericStepper添加百分号"
author: "AS3"
date: "2011-07-26T23:32:32Z"
tags: []
categories: ["Web前端"]
slug: "numericstepper"
draft: false
lastmod: "2011-07-26T23:32:32Z"
id: 1133505
url: "https://as3.iteye.com/blog/1133505"
---

请问 NumericStepper组件中添加百分号

最佳答案 [ticore](http://bbs.9ria.com/space.php?username=ticore) [![](http://uc.9ria.com/data/avatar/000/00/91/09_avatar_small.jpg)](http://bbs.9ria.com/space.php?uid=9109)

*本帖最后由 ticore 于 2011-7-26 15:50 编辑*

自訂一個 MyNumericStepperSkin.mxml 套用到 NumericStepper 上

在 MyNumericStepperSkin.mxml 裡面的 &lt;s:TextInput id="textDisplay"  /&gt;

再自訂一個 MyNumericStepperTextInputSkin.mxml

加一個 Label 顯示 % 就好了

01. ...
02. &lt;!-- text --&gt;
03. &lt;!--- @copy spark.components.supportClasses.SkinnableTextBase#textDisplay --&gt;
04. &lt;s:RichEditableText id="textDisplay"
05. lineBreak="explicit"
06. verticalAlign="middle"
07. multiline="false"
08. left="1" right="1" top="1" bottom="1"
09. paddingLeft="3" paddingTop="6"
10. paddingRight="6" paddingBottom="3"/&gt;
11. &lt;s:Label text="%" verticalAlign="middle" right="3" top="1" bottom="1"  /&gt;
12. .....

*复制代码*

textDisplay.right = 14 + 1;  
為了拉開右邊的空白給 % 用

01. ...
02. override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
03. {
04. if (getStyle("borderVisible") == true)
05. {
06. border.visible = true;
07. shadow.visible = true;
08. background.left = background.top = background.right = background.bottom = 1;
09. textDisplay.left = textDisplay.top = textDisplay.right = textDisplay.bottom = 1;
10. textDisplay.right = 14 + 1;
11. }
12. else
13. {
14. border.visible = false;
15. shadow.visible = false;
16. background.left = background.top = background.right = background.bottom = 0;
17. textDisplay.left = textDisplay.top = textDisplay.right = textDisplay.bottom = 0;
18. textDisplay.right = 10;
19. }
20. borderStroke.color = getStyle("borderColor");
21. borderStroke.alpha = getStyle("borderAlpha");
22. super.updateDisplayList(unscaledWidth, unscaledHeight);
23. }
24. ....

*复制代码*

最後顯示效果像這樣