这是一个轻量级可定制的日历弹出视图,用于范围选择,灵感来自 Google 的 Material 设计指南和应用。
已在 iOS 7、iOS 8 和 iOS 9 上进行了测试。目前仅支持纵向模式。
我建议使用 CocoaPods!只需将此行添加到您的 Podfile:
pod 'SSMaterialCalendarPicker'
使用方法非常简单!
// Add it on the keyWindow if you're using an UINavigationBar
datePicker = [SSMaterialCalendarPicker initCalendarOn:[UIApplication sharedApplication].keyWindow withDelegate:self];
// If there's a fullscreen view, add it there
datePicker = [SSMaterialCalendarPicker initCalendarOn:self.view withDelegate:self];
// Set a Locale if you want to force the localization - otherwise, it uses the device's default locale
datePicker.forceLocale = [NSLocale localeWithLocaleIdentifier:@"pt_BR"];
// Set a warning message for disabled intervals. Default is "WARNING: Interval unavailable!"
datePicker.disabledIntervalWarning = @"Anfitrião indisponível neste período!";
// Set a calendar title. Default is "Select an Interval"
datePicker.calendarTitle = @"Selecione um Período";
// Set apply button title. Default is "Apply"
// OBS: this is hidden on single date mode
datePicker.okButtonText = @"Aplicar";
// Set a primary and a secondary color
datePicker.primaryColor = [UIColor colorWithRed:255/255.0f green:87/255.0f blue:34/255.0f alpha:1.0f];
datePicker.secondaryColor = [UIColor colorWithRed:244/255.0f green:81/255.0f blue:30/255.0f alpha:1.0f];
// Set disabled dates. Dates previous to the current date are disabled by default.
datePicker.disabledDates = @[[NSDate daysFromNow:arc4random_uniform(300)], [NSDate daysFromNow:arc4random_uniform(300)]];
// Set single date mode as YES, if needed
datePicker.singleDateMode = YES;
[datePicker showAnimated];
// .h code:
#import "SSMaterialCalendarPicker.h"
@interface ExampleViewController : UIViewController <SSMaterialCalendarPickerDelegate>
// .m code:
- (void)rangeSelectedWithStartDate:(NSDate *)startDate andEndDate:(NSDate *)endDate {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"pt_BR"]];
[formatter setDateFormat:@"EEEE, dd 'de' MMMM 'de' YYYY"];
[self.startDateLabel setText:[NSString stringWithFormat:@"Entrada: %@", [formatter stringFromDate:startDate]]];
[self.endDateLabel setText:[NSString stringWithFormat:@"Saída: %@", [formatter stringFromDate:endDate]]];
}
如果您有任何反馈、疑问,或者出于某种原因想要对我大喊大叫,请通过电子邮件发给我 [email protected]。该项目上的任何帮助都备受欢迎!
如果您最终使用了这个组件,我很乐意了解您的应用程序并查看它!
MIT 许可证
版权所有 (c) 2015 Shoryuken Solutions ([email protected])
在此特此免费向任何获得本软件及其相关文档文件(“软件”)副本的人授权,在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许将软件提供给其他人,以便他们可以这样做,但受以下条件约束:
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
本软件按“现状”提供,不提供任何形式的保证,无论是明示的、暗示的,还是关于适销性、满足特定用途和侵权性的保证。在任何情况下,作者或版权持有者不应对任何主张、损害或其他责任负有责任,无论该责任产生于合同行为、侵权行为或其他行为,无论是在软件或其使用或其他方式中产生、源于或与软件或其使用或其他方式有关。