From 83e7748e4e95dc0ebaa934c9fa063370a5269449 Mon Sep 17 00:00:00 2001 From: Wenchao Ding Date: Wed, 4 Mar 2015 14:54:24 +0800 Subject: [PATCH] Move layer operation to layoutSublayersOfLayer Move layer operation to layoutSublayersOfLayer Update screenshot --- Pod/Classes/FSCalendarUnit.m | 51 ++++++++++++++++++++---------------- README-cn.md | 3 ++- README.md | 4 +-- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Pod/Classes/FSCalendarUnit.m b/Pod/Classes/FSCalendarUnit.m index ed2cc6d..9337551 100644 --- a/Pod/Classes/FSCalendarUnit.m +++ b/Pod/Classes/FSCalendarUnit.m @@ -98,26 +98,41 @@ return self; } +- (void)layoutSublayersOfLayer:(CALayer *)layer +{ + [super layoutSublayersOfLayer:layer]; + if (layer == self.layer) { + CGFloat diameter = self.diameter; + _animLayer.frame = CGRectMake((self.fs_width-diameter)/2, (_titleLabel.fs_height-diameter)/2, diameter, diameter); + switch (self.style) { + case FSCalendarUnitStyleCircle: + _animLayer.path = [UIBezierPath bezierPathWithOvalInRect:_animLayer.bounds].CGPath; + break; + case FSCalendarUnitStyleRectangle: + _animLayer.path = [UIBezierPath bezierPathWithRect:_animLayer.bounds].CGPath; + break; + default: + break; + } + _animLayer.fillColor = [self unitColorForState:self.absoluteState].CGColor; + + + _eventLayer.frame = CGRectMake((_animLayer.frame.size.width-5)/2+_animLayer.frame.origin.x, CGRectGetMaxY(_animLayer.frame), 5, 5); + _eventLayer.path = [UIBezierPath bezierPathWithOvalInRect:_eventLayer.bounds].CGPath; + _eventLayer.hidden = ![self.dataSource hasEventForUnit:self]; + + if ([self isSelected]) { + [self showAnimation]; + } + } +} + - (void)layoutSubviews { [super layoutSubviews]; - _titleLabel.frame = self.bounds; _titleLabel.fs_left = (self.fs_width - _titleLabel.fs_width)/2.0; - CGFloat diameter = self.diameter; - _animLayer.frame = CGRectMake((self.fs_width-diameter)/2, (_titleLabel.fs_height-diameter)/2, diameter, diameter); - switch (self.style) { - case FSCalendarUnitStyleCircle: - _animLayer.path = [UIBezierPath bezierPathWithOvalInRect:_animLayer.bounds].CGPath; - break; - case FSCalendarUnitStyleRectangle: - _animLayer.path = [UIBezierPath bezierPathWithRect:_animLayer.bounds].CGPath; - break; - default: - break; - } - _animLayer.fillColor = [self unitColorForState:self.absoluteState].CGColor; if (_date) { // set attribute title @@ -142,14 +157,6 @@ _titleLabel.attributedText = attributeString; _titleLabel.fs_top += _titleFont.lineHeight * 0.1; } - - _eventLayer.frame = CGRectMake((_animLayer.frame.size.width-5)/2+_animLayer.frame.origin.x, CGRectGetMaxY(_animLayer.frame), 5, 5); - _eventLayer.path = [UIBezierPath bezierPathWithOvalInRect:_eventLayer.bounds].CGPath; - _eventLayer.hidden = ![self.dataSource hasEventForUnit:self]; - - if ([self isSelected]) { - [self showAnimation]; - } } #pragma mark - Public diff --git a/README-cn.md b/README-cn.md index 175a345..d3f33ab 100644 --- a/README-cn.md +++ b/README-cn.md @@ -2,7 +2,8 @@ ## 特点 ### 1. 手势+方向支持 -![animate](https://cloud.githubusercontent.com/assets/5186464/6260896/de303034-b820-11e4-9f01-8d98e0ac94aa.gif) +![animate](https://cloud.githubusercontent.com/assets/5186464/6260896/de303034-b820-11e4-9f01-8d98e0ac94aa.gif) +![fscalendar-click](https://cloud.githubusercontent.com/assets/5186464/6479246/6156c458-c27d-11e4-97da-52b424b45ec3.gif) ### 2. 自定义颜色样式 ![appearance](https://cloud.githubusercontent.com/assets/5186464/6208969/20ee842a-b5fb-11e4-8875-132d42893b9e.png) diff --git a/README.md b/README.md index 0feaef6..4f829a9 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ ##[中文文档](https://github.com/f33chobits/FSCalendar/blob/master/README-cn.md) ## Features ### 1. Smooth Scrolling and directions(vertical/horizotal) -![animate](https://cloud.githubusercontent.com/assets/5186464/6260896/de303034-b820-11e4-9f01-8d98e0ac94aa.gif) - +![animate](https://cloud.githubusercontent.com/assets/5186464/6260896/de303034-b820-11e4-9f01-8d98e0ac94aa.gif) +![fscalendar-click](https://cloud.githubusercontent.com/assets/5186464/6479246/6156c458-c27d-11e4-97da-52b424b45ec3.gif) ### 2. Appearance adjustment ![appearance](https://cloud.githubusercontent.com/assets/5186464/6208969/20ee842a-b5fb-11e4-8875-132d42893b9e.png)