-
将项目中SGPickerView_DatePicker文件夹拖入工程
-
导入#import "SGPicker.h"头文件
-
通过 alloc init 方法创建
SGPickerView *pickerView = [[SGPickerView alloc] init];
pickerView.pickerViewType = SGPickerViewTypeCenter; // 默认pickerViewType为SGPickerViewTypeBottom, 要想 pickerViewType 属性起到作用, 一定要在对象方法 show 之前设置
[pickerView show];
pickerView.locationMessage = ^(NSString *str){
self.title = str;
};
SGDatePicker *datePicker = [[SGDatePicker alloc] init];
datePicker.datePickerType = SGPickerViewTypeCenter; // 默认datePickerType为SGPickerViewTypeBottom, 要想日期设置起到作用:一定设在 datePickerMode 属性之前设置
datePicker.isBeforeTime = YES;
datePicker.datePickerMode = UIDatePickerModeDate; // 日期一定要设置
__weak typeof(self) weakSelf = self;
[datePicker didFinishSelectedDate:^(NSDate *selectedDate) {
weakSelf.title = [self dateStringWithDate:selectedDate DateFormat:@"yyyy年MM月dd日"]; // 日期设置
weakSelf.title = [self dateStringWithDate:selectedDate DateFormat:@"MM月dd日 HH:mm"]; // 时间设置
}];
[datePicker show];