Created
March 25, 2014 12:38
-
-
Save zzz6519003/9761010 to your computer and use it in GitHub Desktop.
A simple category that creates a relection view for your UIImageView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIImageView+Reflect.h | |
// UIImageView-Reflect | |
// | |
// Created by Snowmanzzz on 3/19/14. | |
// Copyright (c) 2014 zzz. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIImageView (Reflect) | |
- (void)reflect; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIImageView+Reflect.m | |
// UIImageView-Reflect | |
// | |
// Created by Snowmanzzz on 3/19/14. | |
// Copyright (c) 2014 zzz. All rights reserved. | |
// | |
#import "UIImageView+Reflect.h" | |
@implementation UIImageView (Reflect) | |
- (void)reflect { | |
CGRect frame = self.frame; | |
frame.origin.y += (frame.size.height + 1); | |
UIImageView *reflectionImageView = [[UIImageView alloc] initWithFrame:frame]; | |
self.clipsToBounds = TRUE; | |
reflectionImageView.contentMode = self.contentMode; | |
[reflectionImageView setImage:self.image]; | |
reflectionImageView.transform = CGAffineTransformMakeScale(1.0, -1.0); | |
CALayer *reflectionLayer = [reflectionImageView layer]; | |
CAGradientLayer *gradientLayer = [CAGradientLayer layer]; | |
gradientLayer.bounds = reflectionLayer.bounds; | |
gradientLayer.position = CGPointMake(reflectionLayer.bounds.size.width / 2, reflectionLayer.bounds.size.height * 0.5); | |
gradientLayer.colors = [NSArray arrayWithObjects: | |
(id)[[UIColor clearColor] CGColor], | |
(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.3] CGColor], nil]; | |
gradientLayer.startPoint = CGPointMake(0.5,0.5); | |
gradientLayer.endPoint = CGPointMake(0.5,1.0); | |
reflectionLayer.mask = gradientLayer; | |
[self.superview addSubview:reflectionImageView]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment