如何在日历视图iPhone中设置图像 [英] how to set images in the calender view iPhone
问题描述
开发基于日历的应用程序,我的客户需要在用户选择的特定日期设置图像。
Im developing a calender based application and in that my client need to set a image on the particular date user selects.
例如,如果我选择1和20,在两个日期都要设置图像。
For example if i select 1 and 20,an image is to be set on both the dates.
现在我可以只为一个日期设置图像,即如果我选择1,则在该日期设置图像,当我选择20时,1上的图像将消失,图像将仅设置为20。
For now i can set the image only for one date i.e if i select 1 the image is set on that date and when i select 20 the image set on 1 will disappear and image will set only for 20.
任何人都可以帮助我如何做到这一点。
Can anyone please help me how to do this.
提前致谢。
推荐答案
我终于找到了解决方案。我在方法中完成了,你的专家可以建议一个更好的方法。
I finally find a solution for this.I done in the method and you experts can suggest a better way for this.
- (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];
}
}
这篇关于如何在日历视图iPhone中设置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!