iphone - 使用 Tapku Calendar 创建透明日历

标签 iphone ios objective-c calendar tapku

首先,我要感谢本网站上所有有用的答案。我大约六个月前开始编程,我学到的许多东西都是从这里的问题/答案中学到的。

我在 iPhone 项目中使用 Tapku 库中的日历,并希望日历图 block 是透明的,以便我可以看到 TKCalendarMonthView View 后面的 View 。

我使用 this tutorial 中的代码实现了 TKCalendarMonthView作者:本杰明· PIL 逊。

然后我删除了平铺图像并尝试了 this answer 中的代码作者:@Jacques,因此 TKCalendarMonthView.m 中的drawrect 函数如下所示:

- (void) drawRect:(CGRect)rect {

//From Jacques' StackOverflow answer (I also put this in the init)
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];


//From Jacques' answer
[[UIColor clearColor] setFill
 ];
UIRectFill(rect);

//Remove CGContextRef
    //CGContextRef context = UIGraphicsGetCurrentContext();
    //UIImage *tile = [UIImage imageWithContentsOfFile:TKBUNDLE(@"TapkuLibrary.bundle/Images/calendar/Month Calendar Date Tile.png")];

CGRect r = CGRectMake(0, 0, 46, 44);

//From Jacques' StackOverflow answer
[[UIColor clearColor] setFill];
UIRectFill(r);

//Remove this sense we won't use the tile image
//CGContextDrawTiledImage(context, r, tile.CGImage);


if(today > 0){
    int pre = firstOfPrev > 0 ? lastOfPrev - firstOfPrev + 1 : 0;
    int index = today +  pre-1;
    CGRect r =[self rectForCellAtIndex:index];
    r.origin.y -= 7;

    //Don't use image here
    //[[UIImage imageWithContentsOfFile:TKBUNDLE(@"TapkuLibrary.bundle/Images/calendar/Month Calendar Today Tile.png")] drawInRect:r];
}

int index = 0;

UIFont *font = [UIFont boldSystemFontOfSize:dateFontSize];
UIFont *font2 =[UIFont boldSystemFontOfSize:dotFontSize];

//Change the font for our dates:
font = [UIFont fontWithName:@"HelveticaNeue-Light" size:dateFontSize];
font2 = [UIFont fontWithName:@"HelveticaNeue-Light" size:dateFontSize];
UIColor *color = [UIColor grayColor];

if(firstOfPrev>0){
    [color set];
    for(int i = firstOfPrev;i<= lastOfPrev;i++){
        r = [self rectForCellAtIndex:index];
        if ([marks count] > 0)
            [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2];
        else
            [self drawTileInRect:r day:i mark:NO font:font font2:font2];
        index++;
    }
}

//Set the color for all dates in the current month that are not today
color = [UIColor colorWithRed:59/255. green:73/255. blue:88/255. alpha:1];


[color set];
for(int i=1; i <= daysInMonth; i++){

    r = [self rectForCellAtIndex:index];
    if(today == i) [[UIColor whiteColor] set];

    if ([marks count] > 0) 
        [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2];
    else
        [self drawTileInRect:r day:i mark:NO font:font font2:font2];
    if(today == i) [color set];
    index++;
}

[[UIColor grayColor] set];
int i = 1;
while(index % 7 != 0){
    r = [self rectForCellAtIndex:index] ;
    if ([marks count] > 0) 
        [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2];
    else
        [self drawTileInRect:r day:i mark:NO font:font font2:font2];
    i++;
    index++;
}

}

问题是现在图 block (CGRect)是黑色的;或者它们正后方的任何 View 都是黑色的,坦率地说,我对 Tapku 的代码有点迷失。谁知道瓷砖为什么是黑色的?或者我应该在 Tapku 代码中的哪里查找?我对核心显卡不太熟悉,所以也许我错过了一些基本/明显的东西。

注意:我还尝试更改 TKCalendarMonthView 的tileBox(这是一个似乎包含日历图 block 的UIScrollView)的颜色,虽然它确实改变了颜色,但并没有影响图 block 的背景颜色。

提前致谢!如果有任何不清楚的地方,请告诉我。

最佳答案

您可以通过以下步骤透明日历图 block

第 1 步

注释TKCalendarMonthView.m中的代码

+ (void) initialize{
    if (self == [TKCalendarMonthTiles class]){
        //tileImage = [UIImage imageWithContentsOfFile:TKBUNDLE(@"calendar/Month Calendar Date Tile.png")];
    } 
}

第 2 步

更改TKCalendarMonthView.m中的代码

添加代码行[self.currentTile setBackgroundColor:[UIColor clearColor]];

行前[self.tileBox addSubview:self.currentTile];

在方法中 - (void)_setupCurrentTileView:(NSDate*)date

所以你的代码看起来像

- (void) _setupCurrentTileView:(NSDate*)date{

    ....

    [self.currentTile setBackgroundColor:[UIColor clearColor]];
    [self.tileBox addSubview:self.currentTile];

    ....

}

关于iphone - 使用 Tapku Calendar 创建透明日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18689626/

相关文章:

ios - 居中对齐 UITableViewCell 的页脚

objective-c - 在两个已知字符串之间搜索一个字符串

iPhone核心数据与Ruby on Rails同步

ios - 我应该使用什么技术来组织这个日期列表?

iphone - 调整 View 大小。没有按我计划的方式工作

ios - iOS 版本之间的 UIToolbar 疯狂

ios - 自定义 UITableViewCell 中的 UITextField 委托(delegate)不会在第一次加载时被调用

javascript - 使用 Javascript 隐藏 iPhone 的键盘

iphone - 如何在 iOS 上做晕影效果?

ios - 手机锁定时 AVSpeechSynthesizer 将无法工作