Move layer operation to layoutSublayersOfLayer

Move layer operation to layoutSublayersOfLayer
Update screenshot
This commit is contained in:
Wenchao Ding 2015-03-04 14:54:24 +08:00
parent 5feed1d818
commit 83e7748e4e
3 changed files with 33 additions and 25 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)