我想在DateChooser/CalendarLayout中查看平日和週末日的不同顏色。我也想這樣使用自定義樣式名(例如實現:?「weekColor」和「weekendColor」Flex DateChooser - 星期/週末天的字體顏色差異
不知道如何可以做到這一點
歡呼, 裏克
我想在DateChooser/CalendarLayout中查看平日和週末日的不同顏色。我也想這樣使用自定義樣式名(例如實現:?「weekColor」和「weekendColor」Flex DateChooser - 星期/週末天的字體顏色差異
不知道如何可以做到這一點
歡呼, 裏克
我做了什麼類似於客戶端,方法是擴展CalendarLayout類以接受這些樣式,並修改相關日子的樣式,然後擴展DateChooser以接受相同的樣式,並將它們傳遞到您的新CalendarLayout類。
它是單調乏味;而且你很可能會遇到私有變量i ssues;但它是可行的。
這花了我幾天,但我發現了它。所以爲了將來的參考:這裏是我的解決方案:
我擴展了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; border-style:none; 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集可以得到不同的顏色比天數
希望這將幫助其他人的未來。花了我很多時間弄清楚:)
確實很乏味......它幾乎看起來像Adobe不希望你觸摸CalendarLayout,幾乎所有東西都是該類中的私有。至少我很高興聽到我走在正確的軌道上。 – 2011-05-06 06:45:58