加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex的边框渐变

发布时间:2020-12-15 05:01:43 所属栏目:百科 来源:网络整理
导读:flex除了application支持背景渐变色外,其它控制都不支持,近日需要这个功能,在网上搜到些资料整理如下: ? 类文件 GradientBorder.as Flex代码?? /**?? ?*?背景渐变色?? ?*?whisht?? ?*?*/?? package?{?? ?????? ????import?flash.display.*;?? ????import

flex除了application支持背景渐变色外,其它控制都不支持,近日需要这个功能,在网上搜到些资料整理如下:

?

类文件

GradientBorder.as

Flex代码??

收藏代码

  1. /**??
  2. ?*?背景渐变色??
  3. ?*?whisht??
  4. ?*?*/??
  5. package?{??
  6. ??????
  7. ????import?flash.display.*;??
  8. ????import?flash.geom.*;??
  9. ????import?flash.utils.*;??
  10. ????import?mx.core.EdgeMetrics;??
  11. ????import?mx.skins.halo.HaloBorder;??
  12. ????import?mx.utils.ColorUtil;??
  13. ????import?mx.utils.GraphicsUtil;??
  14. ????public?class?GradientBorder?extends?HaloBorder???
  15. ????{??
  16. ??????????
  17. ????????private?var?topCornerRadius:Number;????????//?top?corner?radius??
  18. ????????private?var?bottomCornerRadius:Number;????//?bottom?corner?radius??
  19. ????????private?var?fillColors:Array;????????????//?fill?colors?(two)??
  20. ????????private?var?setup:Boolean;??
  21. ??
  22. ????????private?function?setupStyles():void??
  23. ????????{??
  24. ????????????fillColors?=?getStyle("fillColors")?as?Array;??
  25. ????????????if?(!fillColors)?fillColors?=?[0xFFFFFF,?0xFFFFFF];??
  26. ??????????????
  27. ????????????topCornerRadius?=?getStyle("cornerRadius")?as?Number;??
  28. ????????????if?(!topCornerRadius)?topCornerRadius?=?0;??????
  29. ????????????bottomCornerRadius?=?getStyle("bottomCornerRadius")?as?Number;??
  30. ????????????if?(!bottomCornerRadius)?bottomCornerRadius?=?topCornerRadius;??????
  31. ????????}??
  32. ????????override?protected?function?updateDisplayList(unscaledWidth:Number,?unscaledHeight:Number):void??
  33. ????????????super.updateDisplayList(unscaledWidth,?unscaledHeight);??????
  34. ????????????setupStyles();??
  35. ????????????var?g:Graphics?=?graphics;??
  36. ????????????var?b:EdgeMetrics?=?borderMetrics;??
  37. ????????????var?w:Number?=?unscaledWidth?-?b.left?-?b.right;??
  38. ????????????var?h:Number?=?unscaledHeight?-?b.top?-?b.bottom;??
  39. ????????????var?m:Matrix?=?verticalGradientMatrix(0,?w,?h);??
  40. ????????????g.beginGradientFill("linear",?fillColors,?[1,0)">1],0)">255],?m);??
  41. ????????????var?tr:Number?=?Math.max(topCornerRadius-2,0)">0);??
  42. ????????????var?br:Number?=?Math.max(bottomCornerRadius- ????????????GraphicsUtil.drawRoundRectComplex(g,?b.left,?b.top,?h,?tr,?br,?br);??
  43. ????????????g.endFill();??
  44. ??????????????????
  45. ????}??
  46. }??

调用示例

Mxml代码?? <?xml?version="1.0"?encoding="utf-8"?>??
  • <mx:Application?xmlns:mx="http://www.adobe.com/2006/mxml"???
  • ????layout="vertical"?backgroundImage=""?backgroundColor="white">??
  • ????<mx:Style>??
  • ????????.gradient??
  • ????????????border-style:?solid;??
  • ????????????border-thickness:?0;??
  • ????????????border-skin:?ClassReference("GradientBorder");??
  • ????????????fill-colors:?#0099FF,?#000099;??
  • ????????????corner-radius:?10;??
  • ????????????drop-shadow-enabled:?true;??
  • ????</mx:Style>??
  • ????<mx:Script>??
  • ????????<![CDATA[??
  • ????????????private?function?changeStyle():void??
  • ????????????{??
  • ????????????????box.setStyle("fillColors",?[col1.value,?col2.value]);??
  • ????????????????box.setStyle("cornerRadius",?corner.value);??
  • ????????????}??
  • ????????]]>??
  • ????</mx:Script>??
  • ????<mx:VBox?id="box"?styleName="gradient"?width="400"?height="300"?verticalAlign="middle"?horizontalAlign="center">??
  • ????????<mx:FormItem?label="Color?1:">??
  • ????????????<mx:ColorPicker?id="col1"?change="changeStyle()"?selectedColor="0x0099FF"/>??
  • ????????</mx:FormItem>??
  • ????????<mx:FormItem?label="Color?2:">??
  • ????????????<mx:ColorPicker?id="col2"?change="changeStyle()"?selectedColor="0x000099"/>??
  • ????????<mx:FormItem?label="Corner?radius:">??
  • ????????????<mx:HSlider?id="corner"?value="10"?minimum="0"?maximum="100"?change="changeStyle()"/>??
  • ????</mx:VBox>??
  • </mx:Application> ?
  • (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读