flex背景渐变色

backgroundGradientColors="[#dddddd,#ffffff]"


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

类文件
GradientBorder.as

Flex代码
/**
* 背景渐变色
* whisht
* */
package {

import flash.display.*;
import flash.geom.*;
import flash.utils.*;

import mx.core.EdgeMetrics;
import mx.skins.halo.HaloBorder;
import mx.utils.ColorUtil;
import mx.utils.GraphicsUtil;

public class GradientBorder extends HaloBorder
{

private var topCornerRadius:Number; // top corner radius
private var bottomCornerRadius:Number; // bottom corner radius
private var fillColors:Array; // fill colors (two)
private var setup:Boolean;


private function setupStyles():void
{
fillColors = getStyle("fillColors") as Array;
if (!fillColors) fillColors = [0xFFFFFF, 0xFFFFFF];

topCornerRadius = getStyle("cornerRadius") as Number;
if (!topCornerRadius) topCornerRadius = 0;

bottomCornerRadius = getStyle("bottomCornerRadius") as Number;
if (!bottomCornerRadius) bottomCornerRadius = topCornerRadius;

}


override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);

setupStyles();

var g:Graphics = graphics;
var b:EdgeMetrics = borderMetrics;
var w:Number = unscaledWidth - b.left - b.right;
var h:Number = unscaledHeight - b.top - b.bottom;
var m:Matrix = verticalGradientMatrix(0, 0, w, h);

g.beginGradientFill("linear", fillColors, [1, 1], [0, 255], m);

var tr:Number = Math.max(topCornerRadius-2, 0);
var br:Number = Math.max(bottomCornerRadius-2, 0);

GraphicsUtil.drawRoundRectComplex(g, b.left, b.top, w, h, tr, tr, br, br);
g.endFill();

}

}
}


调用示例
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>
<mx:FormItem label="Corner radius:">
<mx:HSlider id="corner" value="10" minimum="0" maximum="100" change="changeStyle()"/>
</mx:FormItem>
</mx:VBox>

</mx:Application>


转载自http://www.iteye.com/topic/419429
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UniApp是一个基于Vue.js开发的跨平台应用框架,它可以帮助开发者构建多个平台的应用程序,包括iOS、Android、H5、以及小程序等。 关于设置行内渐变色,这通常是指在文本或其他元素内部创建渐变效果。这可以通过CSS(级联样式表)来实现。以下是一个基本的例子: ```html <template> <view class="container"> <text class="gradient-text" :style="gradientStyle">这是一个带有渐变色的文本</text> </view> </template> <style> .container { display: flex; align-items: center; justify-content: center; height: 100vh; } .gradient-text { width: 100%; height: 100%; font-size: 24px; color: #fff; } .gradient-text.text-gradient { background: linear-gradient(to right, red, orange); border-radius: 10px; } </style> ``` 在这个例子中,`.gradient-text` 类的元素设置了背景色渐变,从红色渐变到橙色。这个渐变的效果会应用在文本的内部,形成一种行内渐变的效果。需要注意的是,这里使用的线性渐变是从左到右的,但你可以根据需要调整渐变的开始和结束颜色,以及其方向。 你还可以通过调整`border-radius`属性来改变渐变的方向和形状。例如,如果你想要一个圆形渐变,你可以将`border-radius`设置为`50%`。如果你想要一个更复杂的渐变效果,你可能需要使用更高级的CSS技术,如`background-clip`属性。 在UniApp中,你可以使用以上方式在Vue组件的样式中设置行内渐变色。记得在开发过程中保持样式和内容的一致性,并进行充分的测试,以确保效果符合你的预期。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值