开发基于日历的应用程序,我的客户需要在用户选择的特定日期设置图像。
例如,如果我选择1和20,则在两个日期都要设置图像。
现在我可以只为一个日期设置图像,如果我选择1在该日期设置图像,当我选择20时,1上的图像将消失,图像将仅设置为20。
任何人都可以帮我解决这个问题。
提前致谢。
答案 0 :(得分:1)
我终于找到了解决方案。我在方法中完成了,你的专家可以为此提出一个更好的方法。
- (void)selectButtonForDate:(NSDate *)aDate {
if (selectedButton >= 0) {
NSDate *todayDate = [CalendarLogic dateForToday];
UIButton *button = [buttonsIndex objectAtIndex:selectedButton];
CGRect selectedFrame = button.frame;
if ([selectedDate compare:todayDate] != NSOrderedSame) {
selectedFrame.origin.y = selectedFrame.origin.y + 1;
selectedFrame.size.width = kCalendarDayWidth;
selectedFrame.size.height = kCalendarDayHeight;
}
button.selected = NO;
button.frame = selectedFrame;
self.selectedButton = -1;
self.selectedDate = nil;
}
if (aDate != nil) {
// Save
CGRect dayFrame;
NSDate *dayDate;
NSInteger numberOfWeeks = 5;
// NSCalendar *calendar = [NSCalendar currentCalendar];
// NSDateComponents *components = [calendar components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:[NSDate date]];
// NSDate *todayDate = [calendar dateFromComponents:components];
for (NSInteger aWeek = 0; aWeek <= numberOfWeeks; aWeek ++) {
CGFloat positionY = (aWeek * kCalendarDayHeight) + 60;
for (NSInteger aWeekday = 1; aWeekday <= numberOfDaysInWeek; aWeekday ++) {
CGFloat positionX = ((aWeekday - 1) * kCalendarDayWidth) - 1;
dayFrame = CGRectMake(positionX, positionY, kCalendarDayWidth, kCalendarDayHeight);
dayDate = [CalendarLogic dateForWeekday:aWeekday
onWeek:aWeek
referenceDate:[name referenceDate]];
// NSLog(@" %@ todaydate [datesIndex objectAtIndex:[sender tag] %@",todayDate,[datesIndex objectAtIndex:[sender tag]]);
// NSDate *mmm = [datesIndex objectAtIndex:[sender tag]];
if ([dayDate isEqualToDate:aDate]) {
NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
flag = 1;
[n addObject:[NSValue valueWithCGRect:dayFrame]];
[currentDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:n] forKey:SaveMonth];
[currentDefaults synchronize];
}
}
}
if(flag == 1){
flag = 0;
for (int i=0;i<[n count];i++){
UIImageView *im = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"call.png"]] ;
CGRect myRect = [[n objectAtIndex:i] CGRectValue];
// NSLog(@"n is %@",n );
// NSLog(@"frame 111111111111111 = %@\n", NSStringFromCGRect(myRect));
im.frame = myRect;
[self addSubview:im];
}
}