我正在使用TKCalendar for iOS的标准实现,因为没有太多的文档,我想知道是否有人知道在一个月中设置自定义图像的简单方法。
非常感谢任何帮助!
答案 0 :(得分:1)
您可以按照以下步骤设置自定义图片
您必须右键单击TapkuLibrary.bundle并选择显示数据包内容
现在,您可以将文件夹视为图像,如果您打开该图像文件夹,则可以看到一些文件夹
在这些文件夹中,您必须打开日历文件夹
您可以看到很多图片。现在你可以随意改变图像
我认为它可以帮到你。
答案 1 :(得分:0)
只需在TapkuLibrary.bundle中编辑图像(右键单击,显示数据包内容)
答案 2 :(得分:0)
不,那是你的所有答案都错了。我想要的是能够将每一天的图像更改为我每天都会选择的自定义图像。 我把代码一起破解并让它工作。如果有人正在寻找如何做到这一点,那就去TKCalendarMonthView.m并找到
- (void) drawRect:(CGRect)rect
方法。现在在这个方法中,复制如下(这是我所拥有的代码的简化版本,所以你必须自己构建它):
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *tile = [UIImage imageWithContentsOfFile:TKBUNDLE(@"TapkuLibrary.bundle/Images/calendar/Month Calendar Date Tile.png")];
CGRect r = CGRectMake(0, 0, 46, 44);
CGContextDrawTiledImage(context, r, tile.CGImage);
int index = 0;
UIFont *font = [UIFont boldSystemFontOfSize:dateFontSize];
UIFont *font2 =[UIFont boldSystemFontOfSize:dotFontSize];
UIColor *color = [UIColor grayColor];
//first do the boxes that are still visible from the previous month
//
//
if(firstOfPrev>0){
[color set];
for(int i = firstOfPrev;i<= lastOfPrev;i++){
r = [self rectForCellAtIndex:index];
///////////////////////////
///////////////////////////
///////////////////////////
int indexMoved = 7;
r.origin.y -= indexMoved; //this moves the block to put it back in it's place
//add an image to the rect - note you can add them over each other
[[UIImage imageNamed:[NSString stringWithFormat:@"t.png"]] drawInRect:r];
r.origin.y += indexMoved; //move back the block
///////////////////////////
///////////////////////////
///////////////////////////
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++;
}
}
//Now to blocks for current month
//
//
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];
///////////////////////////
///////////////////////////
///////////////////////////
int indexMoved = 7;
r.origin.y -= indexMoved; //this moves the block to put it back in it's place
//add an image to the rect - note you can add them over each other
[[UIImage imageNamed:[NSString stringWithFormat:@"t.png"]] drawInRect:r];
r.origin.y += indexMoved; //move back the block
///////////////////////////
///////////////////////////
///////////////////////////
if(today == i){ //this is done to highlight today's block
int indexMoved = 7;
r.origin.y -= indexMoved;
[[UIColor colorWithRed:59/255. green:73/255. blue:88/255. alpha:1] set];
//set the image to whatever you want today's block to have
[[UIImage imageNamed:[NSString stringWithFormat:@"Tile-Border-Green.png"]] drawInRect:r];
r.origin.y += indexMoved;
}
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++;
}
//Finally, do blocks for the next month who's blocks are visible
//
//
[[UIColor grayColor] set];
int i = 1;
while(index % 7 != 0){
r = [self rectForCellAtIndex:index] ;
///////////////////////////
///////////////////////////
///////////////////////////
int indexMoved = 7;
r.origin.y -= indexMoved; //this moves the block to put it back in it's place
//add an image to the rect - note you can add them over each other
[[UIImage imageNamed:[NSString stringWithFormat:@"t.png"]] drawInRect:r];
r.origin.y += indexMoved; //move back the block
///////////////////////////
///////////////////////////
///////////////////////////
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++;
}
请注意,它分为三个主要区域(每个区域都有一个for循环)。这些(按顺序)是前一个月仍然可见的块,来自当前月份的块,最后是当前视图中可见的来自下个月的块。
我真的希望这对某人有所帮助,因为设置起来很麻烦!
干杯!