This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathHASectionHeader.m
90 lines (69 loc) · 3.2 KB
/
HASectionHeader.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// HASectionHeader.m
// Paper
//
// Created by Istvan Balogh on 19/10/14.
// Copyright (c) 2014 Heberti Almeida. All rights reserved.
//
#import "HASectionHeader.h"
@interface HASectionHeader () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *reflectedImage;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
@property (nonatomic, strong) IBOutletCollection(UIImageView) NSArray *imageViews;
@property (weak, nonatomic) IBOutlet UILabel *logoLabel;
@property (weak, nonatomic) IBOutlet UILabel *subTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@end
@implementation HASectionHeader
-(void)awakeFromNib{
self.reflectedImage.image = [self.imageViews[0] image];
self.reflectedImage.transform = CGAffineTransformMakeScale(1.0, -1.0);
self.clipsToBounds = YES;
self.layer.cornerRadius = 4;
// Gradient to top image
for (UIImageView* imageView in self.imageViews) {
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.colors = @[(id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4] CGColor],
(id)[[UIColor colorWithWhite:0 alpha:0] CGColor]];
gradient.frame = imageView.bounds;
[imageView.layer insertSublayer:gradient atIndex:0];
}
// Gradient to reflected image
CAGradientLayer *gradientReflected = [CAGradientLayer layer];
gradientReflected.frame = self.reflectedImage.bounds;
gradientReflected.colors = @[(id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor],
(id)[[UIColor colorWithWhite:0 alpha:0] CGColor]];
[self.reflectedImage.layer insertSublayer:gradientReflected atIndex:0];
// Label Shadow
[self.logoLabel setClipsToBounds:NO];
[self.logoLabel.layer setShadowOffset:CGSizeMake(0, 0)];
[self.logoLabel.layer setShadowColor:[[UIColor blackColor] CGColor]];
[self.logoLabel.layer setShadowRadius:1.0];
[self.logoLabel.layer setShadowOpacity:0.6];
// Label Shadow
[self.titleLabel setClipsToBounds:NO];
[self.titleLabel.layer setShadowOffset:CGSizeMake(0, 0)];
[self.titleLabel.layer setShadowColor:[[UIColor blackColor] CGColor]];
[self.titleLabel.layer setShadowRadius:1.0];
[self.titleLabel.layer setShadowOpacity:0.6];
// SubTitleLabel Shadow
[self.subTitleLabel setClipsToBounds:NO];
[self.subTitleLabel.layer setShadowOffset:CGSizeMake(0, 0)];
[self.subTitleLabel.layer setShadowColor:[[UIColor blackColor] CGColor]];
[self.subTitleLabel.layer setShadowRadius:1.0];
[self.subTitleLabel.layer setShadowOpacity:0.6];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth;
NSInteger newPage = lround(fractionalPage);
if (self.pageControl.currentPage != newPage) {
self.reflectedImage.image = [self.imageViews[newPage] image];
self.pageControl.currentPage = newPage;
if (self.didPagControllerChanged) {
self.didPagControllerChanged(newPage);
}
}
}
@end