gpt4 book ai didi

iphone - 如何在日历 View 中设置图像 iPhone

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:16 25 4
gpt4 key购买 nike

我正在开发一个基于日历的应用程序,我的客户需要在用户选择的特定日期设置图像。

例如,如果我选择 1 和 20,则将在这两个日期设置图像。

现在我只能为一个日期设置图像,即如果我选择 1,则在该日期设置图像,当我选择 20 时,在 1 上设置的图像将消失,图像将仅为 20 设置。

任何人都可以帮助我如何做到这一点。

提前致谢。 enter image description here

最佳答案

我终于找到了解决这个问题的方法。我在方法中完成了,你们专家可以为此提出更好的方法。

- (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 - 如何在日历 View 中设置图像 iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9292889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com