gpt4 book ai didi

ios - 使用 UIPIckerView 自定义 DatePicker

转载 作者:行者123 更新时间:2023-11-29 03:34:08 27 4
gpt4 key购买 nike

我是 ios 开发的新手。我正在使用 uipickerview 制作自定义日期选择器。我有 datesArray 用作 uipickerview 的数据源。

我想知道如何只显示标签:今天、明天、星期五、星期六、星期日、星期一、星期二和格式为“EEE, LLL d”的休息日期。

我试过这段代码,但没有用。

for(int i=0;i<22;i++)
{
NSDate *myDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * i];
NSDate *now=[NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateFormat:@"EEE, LLL d"];
if(myDate==now)
{
NSString *myDateString=@"today";
[datesArray addObject:myDateString];
}
else
{
NSString *myDateString = [dateFormatter stringFromDate:myDate];

[datesArray addObject:myDateString];
}

}

最佳答案

试试这个,希望对你有帮助

 NSString *dateFromWS = @"2013-10-16";//im taking it as static you have to take string coming from webservice

for (int i = 0; i < 22; i++)
{
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd"];
NSDate *myDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * i];
NSDate *now = [dateFormatter1 dateFromString:dateFromWS];
NSDate *tomorrow = [NSDate dateWithTimeInterval:60 * 60 * 24 * 1 sinceDate:now];
//NSDate *dummy = [NSDate dateWithTimeInterval:60 * 60 * 24 * 1 sinceDate:now];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateFormat:@"EEE, LLL d"];
NSString *loopDate = [dateFormatter stringFromDate:myDate];
NSString *today = [dateFormatter stringFromDate:now];
NSString *tomorrowString = [dateFormatter stringFromDate:tomorrow];
if ([loopDate isEqualToString:today]) {
[datesArray addObject:@"today"];
} else if ([loopDate isEqualToString:tomorrowString]) {
[datesArray addObject:@"tomorrow"];
} else if ((i/7) < 1) {
[datesArray addObject:[loopDate substringToIndex:3]];
} else {
[datesArray addObject:loopDate];
}
}

关于ios - 使用 UIPIckerView 自定义 DatePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19401805/

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