| | |
| | | #import "ViewController.h" |
| | | #import "Lunar.h" |
| | | |
| | | #define kWidth [UIScreen mainScreen].bounds.size.width |
| | | #define kHeight [UIScreen mainScreen].bounds.size.height |
| | | #define kStatusBarHeight [UIApplication sharedApplication].statusBarFrame.size.height |
| | | |
| | | @interface ViewController () |
| | | |
| | | @property (nonatomic, strong) NSDateFormatter *dateFormatter; |
| | | |
| | | @property (nonatomic, strong) UIButton *dateBtn; |
| | | @property (nonatomic, strong) UITextView *textView; |
| | | @property (nonatomic, strong) UIDatePicker *picker; |
| | | @property (nonatomic, strong) UIButton *cancelBtn; |
| | | @property (nonatomic, strong) UIButton *confirmBtn; |
| | | |
| | | |
| | | @end |
| | | |
| | |
| | | { |
| | | [super viewDidLoad]; |
| | | |
| | | self.view.backgroundColor = [UIColor redColor]; |
| | | self.view.backgroundColor = [UIColor whiteColor]; |
| | | |
| | | Solar *d = [Solar fromYmdHms:1901 :1 :1 :0 :0 :0]; |
| | | // Solar *d = [Solar fromDate:[NSDate new]]; |
| | | NSLog(@"公历:%@", [d toFullString]); |
| | | [self.view addSubview:self.dateBtn]; |
| | | [self.view addSubview:self.textView]; |
| | | |
| | | [self buildUI:[NSDate date]]; |
| | | } |
| | | |
| | | - (void)dateClick:(UIButton *)sender |
| | | { |
| | | [self.view addSubview:self.picker]; |
| | | [self.dateBtn addSubview:self.cancelBtn]; |
| | | [self.dateBtn addSubview:self.confirmBtn]; |
| | | } |
| | | |
| | | - (void)actionBtnClick:(UIButton *)sender |
| | | { |
| | | [self.picker removeFromSuperview]; |
| | | [self.cancelBtn removeFromSuperview]; |
| | | [self.confirmBtn removeFromSuperview]; |
| | | if (sender.tag == 2) { |
| | | [self buildUI:self.picker.date]; |
| | | } |
| | | } |
| | | |
| | | - (void)buildUI:(NSDate *)date |
| | | { |
| | | NSString *dateStr = [self.dateFormatter stringFromDate:date]; |
| | | [self.dateBtn setTitle:dateStr forState:UIControlStateNormal]; |
| | | |
| | | NSString *dataStr = [self buildData:date]; |
| | | self.textView.text = dataStr; |
| | | } |
| | | |
| | | - (NSString *)buildData:(NSDate *)date |
| | | { |
| | | NSMutableString *str = [NSMutableString string]; |
| | | |
| | | Solar *d = [Solar fromDate:date]; |
| | | |
| | | Lunar *l = [d getLunar]; |
| | | [str appendFormat:@"农历:%@\n", [l toString]]; |
| | | [str appendFormat:@"\n年:%@年 属%@ %@\n", [l getYearInGanZhi], [l getYearShengXiao], [l getYearNaYin]]; |
| | | [str appendFormat:@"\n月:%@月 属%@ %@\n", [l getMonthInGanZhi], [l getMonthShengXiao], [l getMonthNaYin]]; |
| | | [str appendFormat:@"\n日:%@日 属%@ %@\n", [l getDayInGanZhi], [l getDayShengXiao], [l getDayNaYin]]; |
| | | [str appendFormat:@"\n儒略日:%@\n", @([d getJulianDay])]; |
| | | |
| | | NSLog(@"农历:%@", [l toString]); |
| | | NSLog(@"年:%@年 属%@ %@", [l getYearInGanZhi], [l getYearShengXiao], [l getYearNaYin]); |
| | | NSLog(@"月:%@月 属%@ %@", [l getMonthInGanZhi], [l getMonthShengXiao], [l getMonthNaYin]); |
| | | NSLog(@"日:%@日 属%@ %@", [l getDayInGanZhi], [l getDayShengXiao], [l getDayNaYin]); |
| | | NSLog(@"儒略日:%@", @([d getJulianDay])); |
| | | |
| | | NSLog(@"月名:%@", [l getSeason]); |
| | | NSLog(@"月相:%@", [l getYueXiang]); |
| | | NSLog(@"物候:%@", [l getWuHou]); |
| | | NSLog(@"六曜:%@", [l getLiuYao]); |
| | | NSLog(@"彭祖百忌:%@ %@", [l getPengZuGan], [l getPengZuZhi]); |
| | | [str appendFormat:@"\n月名:%@\n", [l getSeason]]; |
| | | [str appendFormat:@"\n月相:%@\n", [l getYueXiang]]; |
| | | [str appendFormat:@"\n物候:%@\n", [l getWuHou]]; |
| | | [str appendFormat:@"\n六曜:%@\n", [l getLiuYao]]; |
| | | [str appendFormat:@"\n彭祖百忌:%@ %@\n", [l getPengZuGan], [l getPengZuZhi]]; |
| | | |
| | | NSArray *arrDayYi = [l getDayYi]; |
| | | NSLog(@"每日宜:%@", arrDayYi.count == 0?@"无":[arrDayYi componentsJoinedByString:@" "]); |
| | | [str appendFormat:@"\n每日宜:%@\n", arrDayYi.count == 0?@"无":[arrDayYi componentsJoinedByString:@" "]]; |
| | | |
| | | NSArray *arrDayJi = [l getDayJi]; |
| | | NSLog(@"每日忌:%@", arrDayJi.count == 0?@"无":[arrDayJi componentsJoinedByString:@" "]); |
| | | [str appendFormat:@"\n每日忌:%@\n", arrDayJi.count == 0?@"无":[arrDayJi componentsJoinedByString:@" "]]; |
| | | |
| | | NSArray *arrDayJiShen = [l getDayJiShen]; |
| | | NSLog(@"吉神宜趋:%@", arrDayJiShen.count == 0?@"无":[arrDayJiShen componentsJoinedByString:@" "]); |
| | | [str appendFormat:@"\n吉神宜趋:%@\n", arrDayJiShen.count == 0?@"无":[arrDayJiShen componentsJoinedByString:@" "]]; |
| | | |
| | | NSArray *arrDayXiongSha = [l getDayXiongSha]; |
| | | NSLog(@"凶煞宜忌:%@", arrDayXiongSha.count == 0?@"无":[arrDayXiongSha componentsJoinedByString:@" "]); |
| | | [str appendFormat:@"\n凶煞宜忌:%@\n", arrDayXiongSha.count == 0?@"无":[arrDayXiongSha componentsJoinedByString:@" "]]; |
| | | |
| | | NSLog(@"相冲:%@日 冲%@", [l getDayShengXiao], [l getDayChongDesc]); |
| | | NSLog(@"岁煞:%@", [l getDaySha]); |
| | | NSLog(@"星宿:%@(%@)", [l getXiu], [l getXiuLuck]); |
| | | NSLog(@"星宿歌诀:%@", [l getXiuSong]); |
| | | [str appendFormat:@"\n相冲:%@日 冲%@\n", [l getDayShengXiao], [l getDayChongDesc]]; |
| | | [str appendFormat:@"\n岁煞:%@\n", [l getDaySha]]; |
| | | [str appendFormat:@"\n星宿:%@(%@)\n", [l getXiu], [l getXiuLuck]]; |
| | | [str appendFormat:@"\n星宿歌诀:%@\n", [l getXiuSong]]; |
| | | |
| | | NSLog(@"贵神方位:阳贵神:%@ 阴贵神:%@", [l getDayPositionYangGuiDesc], [l getDayPositionYinGuiDesc]); |
| | | NSLog(@"喜神方位:%@", [l getDayPositionXiDesc]); |
| | | NSLog(@"福神方位:%@", [l getDayPositionFuDesc]); |
| | | NSLog(@"财神方位:%@", [l getDayPositionCaiDesc]); |
| | | [str appendFormat:@"\n贵神方位:阳贵神:%@ 阴贵神:%@\n", [l getDayPositionYangGuiDesc], [l getDayPositionYinGuiDesc]]; |
| | | [str appendFormat:@"\n喜神方位:%@\n", [l getDayPositionXiDesc]]; |
| | | [str appendFormat:@"\n福神方位:%@\n", [l getDayPositionFuDesc]]; |
| | | [str appendFormat:@"\n财神方位:%@\n", [l getDayPositionCaiDesc]]; |
| | | |
| | | NSLog(@"本月胎神:%@", [l getMonthPositionTai]); |
| | | NSLog(@"今日胎神:%@", [l getDayPositionTai]); |
| | | NSLog(@"值星:%@", [l getZhiXing]); |
| | | NSLog(@"十二天神:%@(%@)%@", [l getDayTianShen], [l getDayTianShenType], [l getDayTianShenLuck]); |
| | | NSLog(@"空亡所值:年=%@ 月=%@ 日=%@", [l getYearXunKong], [l getMonthXunKong], [l getDayXunKong]); |
| | | [str appendFormat:@"\n本月胎神:%@\n", [l getMonthPositionTai]]; |
| | | [str appendFormat:@"\n今日胎神:%@\n", [l getDayPositionTai]]; |
| | | [str appendFormat:@"\n值星:%@\n", [l getZhiXing]]; |
| | | [str appendFormat:@"\n十二天神:%@(%@)%@\n", [l getDayTianShen], [l getDayTianShenType], [l getDayTianShenLuck]]; |
| | | [str appendFormat:@"\n空亡所值:年=%@ 月=%@ 日=%@\n", [l getYearXunKong], [l getMonthXunKong], [l getDayXunKong]]; |
| | | |
| | | NineStar *dayNineStar = [l getDayNineStar]; |
| | | [dayNineStar toFullString]; |
| | | NSLog(@"九星:%@%@-%@星(%@)-%@", [dayNineStar getNumber],[dayNineStar getColor], [dayNineStar getNameInTaiYi], [dayNineStar getWuXing], [dayNineStar getTypeInTaiYi]); |
| | | NSLog(@"九星歌诀:%@", [dayNineStar getSongInTaiYi]); |
| | | [str appendFormat:@"\n九星:%@%@-%@星(%@)-%@\n", [dayNineStar getNumber],[dayNineStar getColor], [dayNineStar getNameInTaiYi], [dayNineStar getWuXing], [dayNineStar getTypeInTaiYi]]; |
| | | [str appendFormat:@"\n九星歌诀:%@\n", [dayNineStar getSongInTaiYi]]; |
| | | |
| | | JieQi * pJQ = [l getPrevJieQi]; |
| | | NSLog(@"上一节气:%@ %@", pJQ.name, [pJQ.solar toString]); |
| | | [str appendFormat:@"\n上一节气:%@ %@\n", pJQ.name, [pJQ.solar toString]]; |
| | | |
| | | JieQi * nJQ = [l getNextJieQi]; |
| | | NSLog(@"下一节气:%@ %@", nJQ.name, [nJQ.solar toString]); |
| | | [str appendFormat:@"\n下一节气:%@ %@\n", nJQ.name, [nJQ.solar toString]]; |
| | | |
| | | NSArray *arrFestivals = [d getFestivals]; |
| | | NSLog(@"节日:%@", arrFestivals.count == 0?@"无":[arrFestivals componentsJoinedByString:@" "]); |
| | | [str appendFormat:@"\n节日:%@\n", arrFestivals.count == 0?@"无":[arrFestivals componentsJoinedByString:@" "]]; |
| | | |
| | | NSArray *arrOtherFestivals = [d getOtherFestivals]; |
| | | NSLog(@"纪念日:%@", arrOtherFestivals.count == 0?@"":[arrOtherFestivals componentsJoinedByString:@" "]); |
| | | [str appendFormat:@"\n纪念日:%@\n", arrOtherFestivals.count == 0?@"无":[arrOtherFestivals componentsJoinedByString:@" "]]; |
| | | |
| | | ShuJiu *shujiu = [l getShuJiu]; |
| | | NSLog(@"数九:%@", shujiu?[shujiu toFullString]:@""); |
| | | [str appendFormat:@"\n数九:%@\n", shujiu?[shujiu toFullString]:@"无"]; |
| | | |
| | | Fu *fu = [l getFu]; |
| | | NSLog(@"数九:%@", fu?[fu toFullString]:@""); |
| | | [str appendFormat:@"\n三伏:%@\n", fu?[fu toFullString]:@"无"]; |
| | | |
| | | return str; |
| | | } |
| | | |
| | | #pragma mark - lazy - |
| | | |
| | | - (NSDateFormatter *)dateFormatter |
| | | { |
| | | if (!_dateFormatter) { |
| | | _dateFormatter = [NSDateFormatter new]; |
| | | _dateFormatter.dateFormat = @"yyyy-MM-dd"; |
| | | } |
| | | return _dateFormatter; |
| | | } |
| | | |
| | | - (UIButton *)dateBtn |
| | | { |
| | | if (!_dateBtn) { |
| | | _dateBtn = [UIButton buttonWithType:UIButtonTypeCustom]; |
| | | [_dateBtn setBackgroundColor:[UIColor lightGrayColor]]; |
| | | _dateBtn.frame = CGRectMake(10, kStatusBarHeight + 10, kWidth-20, 40); |
| | | [_dateBtn addTarget:self action:@selector(dateClick:) forControlEvents:UIControlEventTouchUpInside]; |
| | | } |
| | | return _dateBtn; |
| | | } |
| | | |
| | | - (UITextView *)textView |
| | | { |
| | | if (!_textView) { |
| | | _textView = [[UITextView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(_dateBtn.frame)+10, kWidth-20, kHeight-(CGRectGetMaxY(_dateBtn.frame)+20))]; |
| | | _textView.editable = NO; |
| | | } |
| | | return _textView; |
| | | } |
| | | |
| | | - (UIDatePicker *)picker |
| | | { |
| | | if (!_picker) { |
| | | _picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.dateBtn.frame)+10, kWidth-20, 150)]; |
| | | _picker.datePickerMode = UIDatePickerModeDate; |
| | | _picker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]; |
| | | _picker.minimumDate = [self.dateFormatter dateFromString:@"1901-01-01"]; |
| | | _picker.maximumDate = [self.dateFormatter dateFromString:@"2099-12-31"]; |
| | | _picker.backgroundColor = [UIColor lightGrayColor]; |
| | | } |
| | | return _picker; |
| | | } |
| | | |
| | | - (UIButton *)cancelBtn |
| | | { |
| | | if (!_cancelBtn) { |
| | | _cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem]; |
| | | [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal]; |
| | | _cancelBtn.frame = CGRectMake(0, 0, 50, CGRectGetHeight(self.dateBtn.frame)); |
| | | [_cancelBtn addTarget:self action:@selector(actionBtnClick:) forControlEvents:UIControlEventTouchUpInside]; |
| | | _cancelBtn.tag = 1; |
| | | } |
| | | return _cancelBtn; |
| | | } |
| | | |
| | | - (UIButton *)confirmBtn |
| | | { |
| | | if (!_confirmBtn) { |
| | | _confirmBtn = [UIButton buttonWithType:UIButtonTypeSystem]; |
| | | [_confirmBtn setTitle:@"确定" forState:UIControlStateNormal]; |
| | | _confirmBtn.frame = CGRectMake(CGRectGetWidth(self.dateBtn.frame)-50, 0, 50, CGRectGetHeight(self.dateBtn.frame)); |
| | | [_confirmBtn addTarget:self action:@selector(actionBtnClick:) forControlEvents:UIControlEventTouchUpInside]; |
| | | _confirmBtn.tag = 2; |
| | | } |
| | | return _confirmBtn; |
| | | } |
| | | |
| | | @end |