用CellRenderer 来改变一些组件的样式下面是改变字体 ,可以接着扩展
package style{
import fl.controls.listClasses.CellRenderer;
import fl.controls.listClasses.ICellRenderer;
import flash.text.TextFormat;
//常规
public class CellStyle1 extends CellRenderer implements ICellRenderer {
public function CellStyle1():void {
super();
}
override protected function drawBackground():void {
var format:TextFormat = new TextFormat();
format.color=0x000000;
format.size=12;
format.font="宋体";
setStyle("textFormat",format);
super.drawBackground();
}
}
}
//
this._dataGrid为DataGrid实例
this._dataGrid.setStyle("cellRenderer",CellStyle1);//设置数据的样式为CellStyle1
为某列设置样式(这里是第一列)
this._dataGrid.getColumnAt(0).cellRenderer = CellStyle1;//设置第一列样式为CellStyle1
类似比如为DataGrid添加图片可以override CellRenderer 的drawLayout方法:
override protected function drawLayout():void {
super.drawLayout();
//trace(this.data["nick_name"]);
if (this.numChildren>=2 && this.getChildAt(1) is TextField) {
this.removeChild(this.getChildAt(1));
}
if (this.numChildren < 2) {
AddHeadIcon();
}
}
//}///end over
//加载图片方法
private function AddHeadIcon():void {
//ShowCellIcon类根据不同的地址加载不同的图片,通过ID得到url
var headIcon:ShowCellIcon = new ShowCellIcon(this.data["url"]);
headIcon.name = "headIcon"+this.data["url"];
this.addChildAt(headIcon,this.numChildren);
headIcon.x = this.width/3;
headIcon.y = 0;
//headIcon.width = 30;
//headIcon.height = 20;
}
浙公网安备 33010602011771号