2016-12-07 28 views
1

我使用荚FSCalendar(https://github.com/WenchaoD/FSCalendar)m和本地化它,我用:如何获得一个月FSCalendar

calendar.locale = Locale(identifier: String) 

但问题是,在翻译月份最后几个字母语法听起来并不好(这是。像“2016年12月”而不是“2016年12月”中的通缉语言) 在故事板上我只有UIView,请你帮忙理解这个盒子中月份的确切答案? 当我明白我可以做水木清华这样

if monthLabel.text.hasPrefix("") { 
monthLabel.text = //change to normal 

} 

回答

1

没错,FSCalendar有错误的执行 - 这是某事。如使用locale.calendar.monthSymbols代替locale.calendar.standaloneMonthSymbols

快速soultion是修复FSCalendar代码文件FSCalendarHeaderView.m

(void)configureCell:(FSCalendarHeaderCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{ 
    case FSCalendarScopeMonth: { 
     //... 
     //... 
     text = [_calendar.formatter stringFromDate:date]; //**1 
    } 
} 

** 1必须改变,以某事物。像

NSDateComponents *cc = [self.calendar.gregorian components:(NSCalendarUnitMonth | NSCalendarUnitYear) fromDate:date]; 

text = [NSString stringWithFormat:@"%@ %ld", _calendar.formatter.standaloneMonthSymbols[cc.month - 1], (long)cc.year]; 
1

俄罗斯语言环境FSCalendarHeaderView.m改变功能

  • (无效)configureCell:(FSCalendarHeaderCell *)细胞atIndexPath:(NSIndexPath *)indexPath

- (void)configureCell:(FSCalendarHeaderCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{ 
    FSCalendarAppearance *appearance = self.calendar.appearance; 
    cell.titleLabel.font = appearance.headerTitleFont; 
    cell.titleLabel.textColor = appearance.headerTitleColor; 
    _calendar.formatter.dateFormat = appearance.headerDateFormat; 
    BOOL usesUpperCase = (appearance.caseOptions & 15) == FSCalendarCaseOptionsHeaderUsesUpperCase; 
    NSString *text = nil; 
    switch (self.calendar.transitionCoordinator.representingScope) { 
     case FSCalendarScopeMonth: { 
      if (_scrollDirection == UICollectionViewScrollDirectionHorizontal) { 
       // 多出的两项需要制空 
       if ((indexPath.item == 0 || indexPath.item == [self.collectionView numberOfItemsInSection:0] - 1)) { 
        text = nil; 
       } else { 
        NSDate *date = [self.calendar.gregorian dateByAddingUnit:NSCalendarUnitMonth value:indexPath.item-1 toDate:self.calendar.minimumDate options:0]; 
        text = [_calendar.formatter stringFromDate:date]; 
       } 
      } else { 
       NSDate *date = [self.calendar.gregorian dateByAddingUnit:NSCalendarUnitMonth value:indexPath.item toDate:self.calendar.minimumDate options:0]; 
       text = [_calendar.formatter stringFromDate:date]; 
      } 
      break; 
     } 
     case FSCalendarScopeWeek: { 
      if ((indexPath.item == 0 || indexPath.item == [self.collectionView numberOfItemsInSection:0] - 1)) { 
       text = nil; 
      } else { 
       NSDate *firstPage = [self.calendar.gregorian fs_middleDayOfWeek:self.calendar.minimumDate]; 
       NSDate *date = [self.calendar.gregorian dateByAddingUnit:NSCalendarUnitWeekOfYear value:indexPath.item-1 toDate:firstPage options:0]; 
       text = [_calendar.formatter stringFromDate:date]; 
      } 
      break; 
     } 
     default: { 
      break; 
     } 
    } 

    NSArray* foo = [text componentsSeparatedByString: @" "]; 
    NSString* firstBit = [foo objectAtIndex: 0]; 

    if ([firstBit isEqualToString:@"января"]) { 
     firstBit = @"январь "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"февраля"]) { 
     firstBit = @"февраль "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"марта"]) { 
     firstBit = @"март "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"апреля"]) { 
     firstBit = @"апрель "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"мая"]) { 
     firstBit = @"май "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"июня"]) { 
     firstBit = @"июнь "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"июля"]) { 
     firstBit = @"июль "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"августа"]) { 
     firstBit = @"август "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"сентября"]) { 
     firstBit = @"сентябрь "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"октября"]) { 
     firstBit = @"октябрь "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"ноября"]) { 
     firstBit = @"ноябрь "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 
    if ([firstBit isEqualToString:@"декабря"]) { 
     firstBit = @"декабрь "; 
     text = [firstBit stringByAppendingString:[foo objectAtIndex: 1]]; 
    } 

    text = usesUpperCase ? text.uppercaseString : text; 
    cell.titleLabel.text = text; 
    [cell setNeedsLayout]; 
} 
+0

这是本地化它在俄罗斯的唯一途径 - 工程完善 – ArtStyle

2

快速解决方案在Swift 3中

首先继承FSCalendarDelegate再加入这个...

func calendarCurrentPageDidChange(_ calendar: FSCalendar) { 

    let currentMonth = calendar.month(of: calendar.currentPage) 
    print("this is the current Month \(currentMonth)") 
} 

这种“currentMonth”将改变你滚动每月日历每次。

0

你可以做到这一点很容易,并很好地用下面的代码:

//objc 
self.calendar.appearence.headerDateFormat = @"LLLL yyyy"; 

//swift 
self.calendar.appearence.headerDateFormat = "LLLL yyyy" 

要了解更多有关日期的格式使用表从http://userguide.icu-project.org/formatparse/datetime