Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
1. Add locale property
2. Fix issue #64
  • Loading branch information
dingwenchao committed Aug 18, 2015
1 parent 157a6fb commit b9ab395
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Example/FSCalendar/LoadViewExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (void)loadView
FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 64, view.frame.size.width, 300)];
calendar.dataSource = self;
calendar.delegate = self;
// calendar.flow = FSCalendarFlowVertical;
calendar.flow = FSCalendarFlowVertical;
calendar.selectedDate = [NSDate fs_dateWithYear:2015 month:2 day:1];
[view addSubview:calendar];
self.calendar = calendar;
Expand Down
2 changes: 1 addition & 1 deletion FSCalendar.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "FSCalendar"
s.version = "0.10.3"
s.version = "0.11.2"
s.summary = "A powerful calendar which supports Appearance, Infinite Scrolling and Subtitle"

s.homepage = "https://github.com/f33chobits/FSCalendar"
Expand Down
1 change: 1 addition & 0 deletions Pod/Classes/FSCalendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ IB_DESIGNABLE
@property (strong, nonatomic) NSDate *today;
@property (strong, nonatomic) NSDate *selectedDate;
@property (strong, nonatomic) NSDate *currentMonth;
@property (strong, nonatomic) NSLocale *locale;

@property (assign, nonatomic) FSCalendarFlow flow;
@property (assign, nonatomic) IBInspectable NSUInteger firstWeekday;
Expand Down
26 changes: 24 additions & 2 deletions Pod/Classes/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ - (void)setSelectedDate:(NSDate *)selectedDate animate:(BOOL)animate forPlacehol

@implementation FSCalendar

@dynamic locale;
@synthesize flow = _flow, firstWeekday = _firstWeekday;

#pragma mark - Life Cycle && Initialize
Expand Down Expand Up @@ -105,7 +106,7 @@ - (void)initialize
_headerHeight = -1;
_calendar = [NSCalendar currentCalendar];

NSArray *weekSymbols = [_calendar shortStandaloneWeekdaySymbols];
NSArray *weekSymbols = _calendar.shortStandaloneWeekdaySymbols;
_weekdays = [NSMutableArray arrayWithCapacity:weekSymbols.count];
UIFont *weekdayFont = [UIFont systemFontOfSize:_appearance.weekdayTextSize];
for (int i = 0; i < weekSymbols.count; i++) {
Expand Down Expand Up @@ -498,6 +499,20 @@ - (void)setDataSource:(id<FSCalendarDataSource>)dataSource
}
}

- (void)setLocale:(NSLocale *)locale
{
if (![_calendar.locale isEqual:locale]) {
_calendar.locale = locale;
_header.dateFormatter.locale = locale;
[self reloadData];
}
}

- (NSLocale *)locale
{
return _calendar.locale;
}

#pragma mark - Public

- (void)reloadData
Expand All @@ -511,14 +526,21 @@ - (void)reloadData
[_weekdays setValue:[UIFont systemFontOfSize:_appearance.weekdayTextSize] forKey:@"font"];
CGFloat width = self.fs_width/_weekdays.count;
CGFloat height = kWeekHeight;
[_calendar.shortStandaloneWeekdaySymbols enumerateObjectsUsingBlock:^(NSString *symbol, NSUInteger index, BOOL *stop) {
if (index >= _weekdays.count) {
*stop = YES;
return;
}
UILabel *weekdayLabel = _weekdays[index];
weekdayLabel.text = symbol;
}];
[_weekdays enumerateObjectsUsingBlock:^(UILabel *weekdayLabel, NSUInteger idx, BOOL *stop) {
NSUInteger absoluteIndex = ((idx-(_firstWeekday-1))+7)%7;
weekdayLabel.frame = CGRectMake(absoluteIndex * width,
_header.fs_height,
width,
height);
}];

[_collectionView reloadData];
if (_selectedDate) {
_supressEvent = YES;
Expand Down
1 change: 1 addition & 0 deletions Pod/Classes/FSCalendarDynamicHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@interface FSCalendarHeader (Dynamic)

@property (readonly, nonatomic) UICollectionView *collectionView;
@property (readonly, nonatomic) NSDateFormatter *dateFormatter;

@end

9 changes: 6 additions & 3 deletions Pod/Classes/FSCalendarHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ - (void)layoutSubviews
[super layoutSubviews];
_collectionView.frame = CGRectMake(0, self.fs_height*0.1, self.fs_width, self.fs_height*0.9);
_collectionView.contentInset = UIEdgeInsetsZero;
_collectionViewFlowLayout.itemSize = CGSizeMake(_collectionView.fs_width * 0.5,
_collectionView.fs_height);
_collectionViewFlowLayout.itemSize = CGSizeMake(
_collectionView.fs_width*((_scrollDirection==UICollectionViewScrollDirectionHorizontal)?0.5:1),
_collectionView.fs_height
);
if (_needsAdjustingMonthPosition) {
_needsAdjustingMonthPosition = NO;
if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal) {
Expand Down Expand Up @@ -159,7 +161,8 @@ - (void)setScrollDirection:(UICollectionViewScrollDirection)scrollDirection
);
_collectionView.contentOffset = newOffset;
if (scrollDirection == UICollectionViewScrollDirectionVertical) {
_collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(0, self.fs_width*0.25, 0, self.fs_width*0.25);
CGFloat inset = self.fs_width * 0.25;
_collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(0, inset, 0, inset);
} else {
_collectionViewFlowLayout.sectionInset = UIEdgeInsetsZero;
}
Expand Down

0 comments on commit b9ab395

Please sign in to comment.