xiaozhuxiong121 / pgdatepicker Goto Github PK
View Code? Open in Web Editor NEW日期选择器,支持年、年月、年月日、年月日时、年月日时分、年月日时分秒、月日、月日时、月日时分、月日时分秒、时、时分、时分秒、分秒、月日周 时分等
License: MIT License
日期选择器,支持年、年月、年月日、年月日时、年月日时分、年月日时分秒、月日、月日时、月日时分、月日时分秒、时、时分、时分秒、分秒、月日周 时分等
License: MIT License
大神 我想按照你的样式 更改为城市选择器 想把数据换掉 请问应该那个地方开始 我没找到你导入数据的地方。。。。
希望大神加个 年-月-第几周...已Star 谢谢大神
根据文档进行Pod,但是提示失败了,请问是我自己的问题还是你传的有问题?
小于10的月日时分秒能不能改成00,01,02,03......格式!!!
PGDatePicker *datePicker = [[PGDatePicker alloc]init];
datePicker.delegate = self;
[datePicker show];
datePicker.datePickerMode = PGDatePickerModeYearAndMonth;
datePicker.minimumDate = [NSDate setYear:2017 month:11];
datePicker.maximumDate = [NSDate setYear:2017 month:12];
[datePicker setDate:_seletedDate];
月份只有11月12月,调用- (void)setDate:(NSDate *)date的时候,这样设置是不起作用的。
查看了下源码。原因在这个方法中- (void)setDate:(NSDate *)date animated:(BOOL)animated
case PGDatePickerModeYearAndMonth:
{
if (components.year > self.maximumComponents.year) {
components.year = self.maximumComponents.year;
}else if (components.year < self.minimumComponents.year) {
components.year = self.minimumComponents.year;
}
NSInteger row = components.year - self.minimumComponents.year;
[self.pickerView selectRow:row inComponent:0 animated:animated];
{
NSInteger row = 0;
NSString *string = [NSString stringWithFormat:@"%ld", components.month];
if ([string integerValue] <= self.monthList.count) {//原因在这里
row = [self.monthList indexOfObject:string];
}
[self.pickerView selectRow:row inComponent:1 animated:animated];
}
}
我添加了个修复的代码。但是只针对PGDatePickerModeYearAndMonth做了处理,其他模式下没用到就没管
case PGDatePickerModeYearAndMonth:
{
if (components.year > self.maximumComponents.year) {
components.year = self.maximumComponents.year;
}else if (components.year < self.minimumComponents.year) {
components.year = self.minimumComponents.year;
}
NSInteger row = components.year - self.minimumComponents.year;
[self.pickerView selectRow:row inComponent:0 animated:animated];
{
//<<<<
__block NSInteger row = 0;
//>>>>
NSString *string = [NSString stringWithFormat:@"%ld", components.month];
if ([string integerValue] <= self.monthList.count) {
row = [self.monthList indexOfObject:string];
}
//<<<<
else if (self.monthList.count > 0){
[self.monthList enumerateObjectsUsingBlock:^(NSString *monthNum, NSUInteger idx, BOOL * _Nonnull stop) {
if ([monthNum isEqualToString:string ]) {
row = idx;
*stop = YES;
}
}];
}
//>>>>
[self.pickerView selectRow:row inComponent:1 animated:animated];
}
}
加了个遍历去获取选中的月份在monthList中的index
版本:通过pod 'PGDatePicker', '>= 2.0'引入
用法:
PGDatePickManager *datePickManager=[[PGDatePickManager alloc]init]; datePickManager.cancelButtonTextColor=BLUEPRIMARY; datePickManager.confirmButtonTextColor=BLUEPRIMARY; datePickManager.isShadeBackgroud=YES; PGDatePicker *datePicker = datePickManager.datePicker; datePicker.datePickerMode=PGDatePickerModeDateHourMinute; datePicker.datePickerType=PGDatePickerType1; datePicker.delegate = self; datePicker.minimumDate=[NSDate new]; datePicker.maximumDate=[TimeUtil getFutureDate:100]; [self.controller presentViewController:datePickManager animated:false completion:nil];
- (void)setDayListForMonthDays:(NSInteger)day { NSMutableArray *days = [NSMutableArray arrayWithCapacity:day]; NSInteger minDay = self.minimumComponents.day, maxDay = self.maximumComponents.day; if (self.currentComponents.year == self.maximumComponents.year) { if (self.currentComponents.month == self.maximumComponents.month) { day = maxDay; } } if (_setDate) { minDay = 1; } // 此处 i 的值应为minDay for (NSUInteger i = 1; i <= day; i++) { [days addObject:[@(i) stringValue]]; } self.dayList = days; }
在设置样式过程中, 选中行的颜色与非选中行的颜色并没有效果区分
datePicker.titleColorForSelectedRow = [UIColor redColor];
datePicker.titleColorForOtherRow = [UIColor blackColor];
- (IBAction)yearAndMonthHandler:(id)sender {
PGDatePicker *datePicker = [[PGDatePicker alloc]init];
datePicker.delegate = self;
[datePicker showWithShadeBackgroud];
datePicker.datePickerType = PGPickerViewType3;
datePicker.datePickerMode = PGDatePickerModeYearAndMonth;
datePicker.minimumDate = [NSDate setYear:2015 month:5];
datePicker.maximumDate = [NSDate setYear:2017 month:10];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSDate *date = [dateFormatter dateFromString: @"2015-08-10 05:04"];
[datePicker setDate:date animated:true];
}
只显示年月的时候。设置最大最小时间限制的时候有两个问题。如果调用setDate:animated:设置一个默认选中的时间,而该时间是月份不全的年份中,那么该年份会显示完整的月份。最小时间限制没有作用。比如最小时间设置为2015年5月。然后setdate为2015年的随便一个月份。那么2015年对应的月份可以选到1~10月,后面的11月12月也没有了,是因为最大时间是2017年10月。就是两个bug
isShadeBackgroud为yes时,present时黑色背景的显示效果不是很理想。可以考虑优化一下,还是以渐变的方式显示出来。
我用strong修饰后 不在闪退
[!] Unable to satisfy the following requirements:
PGDatePicker (>= 2.0)
required by Podfile
None of your spec sources contain a spec satisfying the dependency: PGDatePicker (>= 2.0)
.
You have either:
pod repo update
or with pod install --repo-update
.Note: as of CocoaPods 1.0, pod repo update
does not happen on pod install
by default.
原来大神是把月日设置为了固定的false 好吧
你好,我想问下,我安装PGDatePicker成功了,但是在import的时候为什么会报错,说PGDatePicker不存在啊
如果日期选择器可以和上面的工具条独立开来可能更加方便
有时显示空白的.
- (void)showDatePicker {
PGDatePicker *datePicker = [[PGDatePicker alloc] init];
datePicker.delegate = self;
datePicker.datePickerMode = PGDatePickerModeYearAndMonth;
NSDateFormatter *dataFormant = [[NSDateFormatter alloc] init];
[dataFormant setDateFormat: @"yyyyMM"];
NSString *newtime = [dataFormant stringFromDate:[NSDate date]];
datePicker.maximumDate = [dataFormant dateFromString:newtime];
if ([EMUtil isValidString: self.model.from]) {
if (!self.chooseFrom) {
//选择了开始时间再去选结束时间
NSDate *mindate = [dataFormant dateFromString:self.model.from];
datePicker.minimumDate = mindate;
}
}
if ([EMUtil isValidString: self.model.to]) {
if (self.chooseFrom) {
// 选择了结束时间再去选开始时间
NSDate *maxdate = [dataFormant dateFromString:self.model.to];
datePicker.maximumDate = maxdate;
}
}
[datePicker show];
}
目前需求是选择开始时间和结束时间,现在选择了开始时间,想要限制结束时间选择框的选择范围在开始时间和当前时间之间。以上是代码。
当[datePicker show]执行后,选择框中的日期范围不对。
请看一下是我的代码有问题,还是这个库实现的有问题。谢谢。
let seledate = NSDate.setYear(2007, month: 10, day: 10)
datePicker.setDate(seledate!)
现在很多日期选择都是可以循环选择的,希望能加这个功能,写的很棒!
打开时间选择,默认显示上一次选中的的时间是
NSDate *date = [NSDate setHour:10 minute:10];
[datePicker setDate:date animated:true];
这样么,
作者大大好!
[UIView animateWithDuration:0.3 animations:^{ self.headerView.frame = CGRectMake(0, kScreenHeight - height - kHeaderViewHeight, kScreenWidth, kHeaderViewHeight); self.frame = CGRectMake(0, CGRectGetMaxY(self.headerView.frame), kScreenWidth, height); }];
这段代码应该加在-show函数的结尾,而不应该在layoutsubviews,因为重复调用show的话,并没有弹出显示。。。
例如设置 2017-9-30最小 2017-10-2最大 ,初始化时日期列显示所有,在滚动第二列后才显示正确的日期选择列
另外, 调用消失后不进行初始化仅调用show方法无效,需要重新初始化或自己修改代码,忘以后完善
个人认为需要添加一个半透明背景的方法。好多设计图弹选择器都加了一个黑色半透明遮罩。
比如增加一个show方法,在用一个属性可以改变遮罩的颜色
在执行show方法之前设定titleLabel属性时无效,原因是在show之前没创建相应的控件。还有titleColorForOtherRow该属性设置无效,望及时解决。
操作如下:
当mode为PGDatePickerModeDate时,选择2018年5月31日,当将月份滚动到4月时,日的那一列不跟年月两列对其。
if self.maxEndDate != nil {
datePicker.maximumDate = self.maxEndDate!
}
if self.minEndDate != nil {
datePicker.minimumDate = self.minEndDate!
}
这样动态的设置区间最大值为默认值加六个月 最小值加一个月 为什么最小值设置正常 最大值设置失败呢?
但是加六个跨年后 设置的区间却是正确的。 不跨年所有情况都是直接显示到12月份
可以简单国际化
不支持8.1
PGDatePicker的 setDate方法如果animated 是yes 的话会造成页面卡顿的定位不准确
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.