我希望在工作日和周末天的DateChooser / CalendarLayout中看到不同的颜色。我还想使用自定义样式名来实现这一点(例如:“weekColor”和“weekendColor”。
知道如何实现这一目标吗?
欢呼, 瑞克
答案 0 :(得分:3)
我花了几天时间才找到它。所以供将来参考:这是我的解决方案:
我扩展了DateChooser并在函数updateDisplayList上添加了一个覆盖(w:Number,h:Number)(在此函数中已经设置了SMTWTFS日期名称)。
在updateDisplayList中,您可以获取mx_internal :: dateGrid.dayBlockArrays [column] [row]包含CalendarLayout的所有值。在该数组/数组中,每列的第一行是SMTWTFS日之一。其他行是dayNumbers。一旦我发现它是一个确定周末日是什么并相应调整颜色的问题。如下所示:
override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
// Now the dayBlocksArray has been filled. The Array looks as follows
// dayBlocksArray["rows"]["columns] .... therefor [i][0 (zero)] will always get the dayNames (SMTWTFS)
// Compare the dayNames with the set this.dayNames (which always start with sunday) and find the weekend days
var colIndex:uint = 0;
var rowIndex:uint = 1; // The first row (SMTWTFS) is handled seperately
var currentColumn:Array;
var dayName:UITextField;
var backgroundColor:uint = this.getStyle("dayNamesBackgroundColor");
var isWeekendCol:Boolean = false;
var currentTextFormat:TextFormat;
// When the style is not found the default of white will be used.
if (!backgroundColor)
{
backgroundColor = 0xFFFFFF;
}
for (colIndex; colIndex < 7; colIndex++)
{
// First determine if the first item in this row (SMTWTFS) is a week/weekend day
currentColumn = mx_internal::dateGrid.dayBlocksArray[colIndex];
dayName = currentColumn[0];
// Determine if this is a weekend row
// The dayNames array is fixed in the order of index 0 = sunday and index 6 = saturday.
// Therefor check of the text value of the current dayName is equal to either of
// those two. If it is we are dealing with a weekend column
isWeekendCol = dayName.text == this.dayNames[0] || dayName.text == this.dayNames[6];
if (isWeekendCol)
{
// Set the color
currentTextFormat = dayName.getTextFormat();
currentTextFormat.color = getStyle("weekendHeaderColor");
dayName.setTextFormat(currentTextFormat);
// Set the background color
dayName.background = true;
dayName.backgroundColor = backgroundColor;
}
else
{
currentTextFormat = dayName.getTextFormat();
currentTextFormat.color = getStyle("weekHeaderColor");
dayName.setTextFormat(currentTextFormat);
// Set the background color
dayName.background = true;
dayName.backgroundColor = backgroundColor;
}
// Reset the rowIndex
rowIndex = 1;
// Now go through all the other rows of this column
for (rowIndex; rowIndex < currentColumn.length; rowIndex++)
{
dayName = currentColumn[rowIndex];
if (isWeekendCol)
{
dayName.setColor(getStyle("weekendColor"));
}
else
{
dayName.setColor(getStyle("weekColor"));
}
}
}
}
在CSS文件中,我添加了以下样式:
DateChooser {
cornerRadius:0;
headerColors:#FFFFFF,#FFFFFF;
todayColor:#00448c;
边框样式:无;
dropShadowEnabled:false;
fontFamily:myGeorgia;
dayNamesBackgroundColor:#ECECEC;
weekHeaderColor:#444444;
weekendHeaderColor:#DDDDDD;
weekColor:#00317F;
weekendColor:#DDDDDD;
headerStyleName:“dateChooserHeaderStyle”;
comboBoxStyleName:“comboBoxStyleName”;
}
这里最有趣的样式是自定义样式“dayNamesBackgroundColor”(用于为SMTWTFS集提供背景颜色)和自定义样式“weekendHeaderColor”,“weekHeaderColor”,“weekColor”,“weekendColor”
我在上面的方法中读取这些颜色,以完全控制周/周末颜色的差异,其中SMTWTFS设置可以获得与白天数不同的颜色
希望这将有助于其他人。花了我很多时间来弄明白:)
答案 1 :(得分:2)
我为客户做了类似的事情。方法是扩展CalendarLayout类以接受这些样式并在相关日期修改样式。然后扩展DateChooser以接受相同的样式并将它们传递给新的CalendarLayout类。
这很乏味;你最有可能遇到私人变量问题;但它是可行的。