1
에 문제가이 코드가 :이 코드는 해당 월의 일에 31 개 레이블을 설정IOS : NSDateComponent
- (void) setDataLabel{
for (int k = 0; k<31; k++){
[[lineSunday objectAtIndex:k] setAlpha:0.00];
[[arrayDay objectAtIndex:k] setTextColor:[UIColor whiteColor]];
}
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setYear:2011];
[components setDay:1];
[components setMonth:10];
//NSLog(@"mese:%d", month);
NSCalendar *gregorianCalendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *firstDate = [gregorianCalendar dateFromComponents:components];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd"];
for (int i = 0; i < 31; i++) {
NSTimeInterval seconds = 24*60*60 * i;
NSDate *date = [NSDate dateWithTimeInterval:seconds sinceDate:firstDate];
NSDateComponents *weekdayComponents = [gregorianCalendar components:NSWeekdayCalendarUnit fromDate:date];
int weekday = [weekdayComponents weekday];
NSString *strDate = [dateFormatter stringFromDate: date];
[[arrayDay objectAtIndex:i] setText:strDate];
if (weekday == 1) {
[[arrayDay objectAtIndex:i] setTextColor:[UIColor redColor]];
[[lineSunday objectAtIndex:i] setAlpha:1.00];
}
}
을 그리고 모든 괜찮아요,하지만 10 월 한 달 동안 지금이 평일이 왜 이해가 안 돼요 연속; 예 : 올해의 달 말 이런 식으로 하루에이 코드 쓰기 :
.... 25 26 27 28 29 30 30
30 및 30은 붉은 색이다, 그러나 그렇게해서는 안됩니다, 그것은
.... 25 26 27 28 29 30 31
만 30
이 일이 왜 redcolour해야해야 하는가?
어떻게 해결할 수 있습니까? – CrazyDev
몇 가지 코드를 추가하고 일부 릴리스를 거기에 넣습니다. – Eiko