完成在 Tapku 库中以单一背景颜色标记日期需要三种颜色 Objective C

发布于 2024-12-03 06:17:36 字数 115 浏览 4 评论 0原文

我正在使用 tapku 库在我的应用程序中显示日历。我已经完成了所有日期计算并根据我的需要正确标记了单元格,但我想根据我的选择为单元格提供不同的颜色。我已经用单一背景颜色进行了标记,但我想以三种颜色显示。我该怎么办?

I am using tapku library for displaying calender in my application. I have done all date calculations and marked the cells properly acccording to my need but I want to give a different color to the cell according to my choice. I have done marking in single background color but I want to display in three colors. How can I?

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

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

发布评论

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

评论(1

渔村楼浪 2024-12-10 06:17:36

看方法:

在drawRect:方法中将颜色设置为[UIColor greyColor](代码如下)。您可以做的是检查该日期是否是您感兴趣的日期,然后适当地更改颜色。我不确定你想如何区分你的约会——这是你的决定;过去,我将 mark 参数的参数更改为 int 之类的参数,然后根据 int 的值设置颜色。标记参数来自标记数组,因此如果您传入具有不同值的数组,然后在整个 TKCalendarMonthView 中更改方法参数,应该没问题。

例如,假设您想要:mark = 1 -->画红色;标记 = 2 -->画绿色;标记> 2 -->画蓝色。

- (void) drawTileInRect:(CGRect)r day:(int)day mark:(**int**)mark font:(UIFont*)f1 font2:(UIFont*)f2
{

    NSString *str = [NSString stringWithFormat:@"%d",day];


    r.size.height -= 2;
    [str drawInRect: r
       withFont: f1
      lineBreakMode: UILineBreakModeWordWrap 
      alignment: UITextAlignmentCenter];

    if (mark) {
        if (mark == 1)
             [[UIColor redColor] set];
        else if (mark == 2)
             [[UIColor greenColor] set];
        else if (mark > 2)
             [[UIColor blueColor] set];
        r.size.height = 10;
        r.origin.y += 18;

        [@"•" drawInRect: r
                withFont: f2
           lineBreakMode: UILineBreakModeWordWrap 
           alignment: UITextAlignmentCenter];
     }
   [[UIColor grayColor] set];

}

希望这能回答您的问题。

Look at the method:

The color is set to [UIColor grayColor] in the drawRect: method (one below in the code). What you can do is check if the date is a date you're interested in and then change the color appropriately. I'm not sure how you want to differentiate between your dates--it's your call; in the past, I've changed the parameter of the mark argument to something like an int and then basing the color on the int's value. The mark argument comes from the marks array, so if you pass in an array with different values and then change the method arguments throughout the TKCalendarMonthView, it should be okay.

For example, lets say you want: mark = 1 --> draw red; mark = 2 --> draw green; mark > 2 --> draw blue.

- (void) drawTileInRect:(CGRect)r day:(int)day mark:(**int**)mark font:(UIFont*)f1 font2:(UIFont*)f2
{

    NSString *str = [NSString stringWithFormat:@"%d",day];


    r.size.height -= 2;
    [str drawInRect: r
       withFont: f1
      lineBreakMode: UILineBreakModeWordWrap 
      alignment: UITextAlignmentCenter];

    if (mark) {
        if (mark == 1)
             [[UIColor redColor] set];
        else if (mark == 2)
             [[UIColor greenColor] set];
        else if (mark > 2)
             [[UIColor blueColor] set];
        r.size.height = 10;
        r.origin.y += 18;

        [@"•" drawInRect: r
                withFont: f2
           lineBreakMode: UILineBreakModeWordWrap 
           alignment: UITextAlignmentCenter];
     }
   [[UIColor grayColor] set];

}

Hope this answers your question.

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