2

まず、このサイトのすべての役立つ回答に感謝します。私は約 6 か月前にプログラミングを始めました。私が学んだことの多くは、ここでの質問/回答からのものです。

iPhone プロジェクトで Tapku ライブラリの Calendar を使用していますが、TKCalendarMonthView ビューの背後にあるビューを表示できるように、カレンダー タイルを透明にしたいと考えています。

Benjamin Pearson によるこのチュートリアルのコードを使用して TKCalendarMonthView を実装しました。

次に、タイル画像を削除し、 @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++;
}

}

問題は、タイル (CGRects) が黒くなっていることです。またはそれらのすぐ後ろにあるビューはすべて黒く、率直に言って、私は Tapku のコードで少し迷っています。タイルが黒い理由を知っている人はいますか?または、Tapku コードのどこを見ればよいのでしょうか? 私は Core Graphics にあまり詳しくないので、基本的/明白な何かが欠けている可能性があります。

注: TKCalendarMonthView の tileBox (カレンダー タイルを含むと思われる UIScrollView) の色も変更しようとしましたが、色は変更されましたが、タイルの背景色には影響しませんでした。

前もって感謝します!また、不明な点があれば教えてください。

4

2 に答える 2

1

最後に、カレンダー ビューで背景色をクリアにする方法を取得します。

以下のようにコードを変更します。

TKCalendarMonthView.m

(1)以下の行をコメント/削除します。

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

(2)- (void) _setupCurrentTileView:(NSDate*)dateメソッド内に以下の行を
追加[self.currentTile setBackgroundColor:[UIColor clearColor]];

- (void) _setupCurrentTileView:(NSDate*)date{
if(self.currentTile) return;

NSDate *month = [date firstOfMonthWithTimeZone:self.timeZone];
NSArray *dates = [TKCalendarMonthTiles rangeOfDatesInMonthGrid:month startOnSunday:self.sunday timeZone:self.timeZone];
NSArray *data = [self.dataSource calendarMonthView:self marksFromDate:dates[0] toDate:[dates lastObject]];

self.currentTile = [[TKCalendarMonthTiles alloc] initWithMonth:month marks:data startDayOnSunday:self.sunday timeZone:self.timeZone];
[self.currentTile setTarget:self action:@selector(_tileSelectedWithData:)];

[self.currentTile setBackgroundColor:[UIColor clearColor]]; // ADD THIS LINE
[self.tileBox addSubview:self.currentTile];

self.monthYear.text = [date monthYearStringWithTimeZone:self.timeZone];
[self _updateSubviewFramesWithTile:self.currentTile];

}
于 2013-11-16T10:18:55.700 に答える