constellation

- (NSString *) astrology {
    NSString *astroString = @"魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯";
    NSString *astroFormat = @"102123444543";
    NSString *result;

    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:self];

    long m = [components month];
    long d = [components day];

    result = [NSString stringWithFormat:@"%@座",[astroString substringWithRange:NSMakeRange(m * 2-(d < [[astroFormat substringWithRange:NSMakeRange((m-1), 1)] intValue] - (-19)) * 2,2)]];

    return result;
}
/**
 *  根据月和日的下标获取星座名
 *
 *  @param monthIndex 月的下标
 *  @param dayIndex   日的下标
 *
 *  @return 星座名
 */
- (NSString *)getConstellationNameByMonthIndex:(NSInteger)monthIndex dayIndex:(NSInteger)dayIndex {
    NSArray *constellations = @[@"水瓶座", @"双鱼座", @"白羊座", @"金牛座", @"双子座", @"巨蟹座", @"狮子座", @"处女座", @"天秤座", @"天蝎座", @"射手座", @"摩羯座"];
    NSInteger index;
    NSArray *conIndexs = @[@(20),@(19),@(21),@(20),@(21),@(22),@(23),@(23),@(23),@(24),@(23),@(22)];
    if ([[conIndexs objectAtIndex:monthIndex] integerValue] <= dayIndex + 1) {
        index = monthIndex;
    } else index = (monthIndex - 1 + 12) % 12;
    return [constellations objectAtIndex:index];
}


   转载规则


《constellation》 志鹏 采用 知识共享署名 4.0 国际许可协议 进行许可。
 上一篇
AutoLayout AutoLayout
一.名词解析intrinsicContentSize:字面意思就是固有的大小。就是说在没有受到约束影响时本来应该有的大小。Content Hugging Priority:字面意识是内容压缩优先级。就是说阻止view返回的实际尺寸比intr
2017-03-08
下一篇 
pod command pod command
pod 基础使用命令 创建Podfile文件 pod init 使用命令打开Podfile文件open -a Xcode Podfile 搜索pod 库pod search 库名 更新本地Repo库pod repo update
2017-03-07
  目录