Flex DateChooser - 周/周末的字体颜色差异

发布于 2024-11-05 13:15:50 字数 141 浏览 4 评论 0原文

我希望在工作日和周末的 DateChooser / CalendarLayout 中看到不同的颜色。我还想使用自定义样式名称来实现这一点(例如:“weekColor”和“weekendColor”。

知道如何实现这一点吗?

欢呼, 瑞克

I would like to see different colors in my DateChooser / CalendarLayout for weekdays and weekend days. I would also like to achieve this using a custom stylename (for example: "weekColor" and "weekendColor".

Any idea how this can be achieved?

Cheer,
Rick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只有一腔孤勇 2024-11-12 13:15:50

我花了几天时间但我发现了。因此,供将来参考:这是我的解决方案:

我扩展了 DateChooser 并在函数 updateDisplayList(w:Number, h:Number) 上添加了覆盖(在此函数中,已设置 SMTWTFS 日期名称)。

在 updateDisplayList 中,您可以获得 mx_internal::dateGrid.dayBlockArrays[column][row] 包含 CalendarLayout 的所有值。在该数组/数组中,每列的第一行是 SMTWTFS 中的某一天。其他行是日期。一旦我发现这一点,就需要确定周末是什么并相应地调整颜色。如下所示:

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;
标题颜色:#FFFFFF、#FFFFFF;
今天颜色:#00448c;
边框样式:无;
dropShadowEnabled:假;
字体家族:myGeorgia;
dayNamesBackgroundColor:#ECECEC;
weekHeaderColor:#444444;
周末标题颜色:#DDDDDD;
周颜色:#00317F;
周末颜色:#DDDDDD;
headerStyleName: "dateChooserHeaderStyle";
comboBoxStyleName: "comboBoxStyleName";
这里最

有趣的样式是自定义样式“dayNamesBackgroundColor”(用于为 SMTWTFS 集提供背景颜色)和自定义样式“weekendHeaderColor”、“weekHeaderColor”、“weekColor”、“weekendColor”

我读了这些颜色在上面的方法中,可以完全控制周/周末颜色的差异,其中 SMTWTFS 设置可能会获得与天数不同的颜色

希望这会在将来帮助其他人。我花了很多时间才弄清楚:)

It took me a couple of days but I found it out. So for future reference: here is my solution:

I extended the DateChooser and added an override on the function updateDisplayList(w:Number, h:Number) (In this function the SMTWTFS day names have been set).

In the updateDisplayList you can get the mx_internal::dateGrid.dayBlockArrays[column][row] Containing all the values for the CalendarLayout. In that array / array the first row on each column is the one of the SMTWTFS days. The other rows are the dayNumbers. Once I found that out it is a matter of determining what a weekend day was and adjust the colors accordingly. As I show below:

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"));
                }
            }
        } 
}

In the CSS file I added the following styles:

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";
}

The most interesting styles here are the custom style "dayNamesBackgroundColor" (which is used to give a background color to the SMTWTFS set) and the custom styles "weekendHeaderColor", "weekHeaderColor", "weekColor", "weekendColor"

I read these colors in the method above to get full control for the difference in week/weekend colors where the SMTWTFS set could get different colors than the day number

Hope this will help other people in the future. Took me a lot of time to figure it out :)

三月梨花 2024-11-12 13:15:50

我为客户做了类似的事情。该方法是扩展 CalendarLayout 类以接受这些样式并修改相关日期的样式。然后扩展 DateChooser 以接受这些相同的样式并将它们传递给新的 CalendarLayout 类。

这很乏味;你很可能会遇到私有变量问题;但这是可行的。

I did something similar for a client. The approach is to extend the CalendarLayout class to accept those styles and modify the styling on the relevant days. Then extend the DateChooser to accept those same styles and pass them on to your new CalendarLayout class.

It's tedious; and you'll most likely run into private variable issues; but it is doable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文