flex 圆形按钮皮肤的制作

要做一个圆形按钮,在flex4里最直接的方法就是为button写一个皮肤。先看下样子:

[img]http://dl.iteye.com/upload/attachment/0078/2411/6f6d58aa-061e-303b-a485-d6fcba3bba15.png[/img]

下面是皮肤的代码:

<?xml version="1.0" encoding="utf-8"?>

<!--
round button
-->
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
minWidth="21" minHeight="21"
alpha.disabled="0.5">

<fx:Metadata>
<![CDATA[
[HostComponent("spark.components.Button")]


]]>
</fx:Metadata>
<fx:Script>
<![CDATA[

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
bg.width = bg.height = Math.max(unscaledWidth, unscaledHeight) - 2;

var cc:Number = Number(getStyle("chromeColor"));
if(isNaN(cc))
{
cc = 0xff0000;
}

bgFill.color = borderStroke.color = cc;

super.updateDisplayList(unscaledWidth, unscaledHeight);
}

]]>
</fx:Script>

<!-- states -->
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>

<!--背景-->
<s:Ellipse id="bg" width="100%" height="100%" left="1" right="1" top="1" bottom="1">
<s:fill>
<s:SolidColor id="bgFill" color="0xffffff" alpha=".6" alpha.over=".8" alpha.down="1"/>
</s:fill>
</s:Ellipse>

<!--边框-->
<s:Ellipse id="border" left="0" right="0" top="0" bottom="0">
<s:stroke>
<s:SolidColorStroke id="borderStroke" color="0" />
</s:stroke>
</s:Ellipse>

<!--文本-->
<s:Label id="labelDisplay"
textAlign="center"
maxDisplayedLines="1"
horizontalCenter="0" verticalCenter="1" verticalAlign="middle"
left="5" right="5" top="2" bottom="2">
</s:Label>

</s:SparkButtonSkin>



使用方式:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:VGroup>
<s:TextInput id="ti"/>
<mx:ColorPicker id="cp"/>
<s:Button skinClass="skins.RoundButtonSkin" label="{ti.text}" chromeColor="{cp.selectedColor}"/>
</s:VGroup>
</s:Application>

s:SparkButtonSkin是sdk4.5+才有的,之前的请改成s:SparkSkin
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用flex布局制作十字架网页的示例代码: ```html <!DOCTYPE html> <html> <head> <title>Flex Cross Layout</title> <style type="text/css"> body { margin: 0; padding: 0; display: flex; flex-direction: column; min-height: 100vh; } header, footer { background-color: #333; color: #fff; padding: 10px; text-align: center; } main { display: flex; flex: 1; } aside { background-color: #f2f2f2; padding: 10px; flex-basis: 200px; } section { flex: 1; display: flex; flex-direction: column; } section > div { flex: 1; display: flex; flex-direction: row; } section > div > div { flex: 1; padding: 10px; } #left-top { background-color: #f2f2f2; } #left-bottom { background-color: #d9d9d9; } #right { background-color: #e6e6e6; } </style> </head> <body> <header> <h1>Header</h1> </header> <main> <aside> <h2>Aside</h2> <p>Some content here</p> </aside> <section> <div> <div id="left-top"> <h2>Left Top</h2> <p>Some content here</p> </div> <div id="right"> <h2>Right</h2> <p>Some content here</p> </div> </div> <div> <div id="left-bottom"> <h2>Left Bottom</h2> <p>Some content here</p> </div> <div id="right"> <h2>Right</h2> <p>Some content here</p> </div> </div> </section> </main> <footer> <h3>Footer</h3> </footer> </body> </html> ``` 这个示例代码使用了flex布局来实现一个十字架网页,其中header和footer分别是顶部和底部的导航栏,main是整个页面的主体部分,包括aside和section两个部分。aside是左侧的导航栏,section是右侧的内容区域,包括两个div,每个div又包括左右两个子div。这个布局可以根据实际需要进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值