Release 0.1.0
This commit is contained in:
1 parent
70488b490a
commit
16c5abc555
188 files changed
+9490
-33
No files matched your search
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// PNGradientView.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 12/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface PNGradientView : UIView
|
||||
|
||||
- (void) setBackgroundLayerWithColors:(NSArray *) colors startPoint:(CGPoint) startPoint;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// PNGradientView.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 12/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "PNGradientView.h"
|
||||
|
||||
@interface PNGradientView()
|
||||
|
||||
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
|
||||
@property (nonatomic, strong) NSMutableArray *colors;
|
||||
@property (nonatomic, strong) NSMutableArray *cgColors;
|
||||
@property (nonatomic) CGPoint startPoint;
|
||||
@property (nonatomic) BOOL didUpdateConstraints;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation PNGradientView
|
||||
|
||||
- (instancetype) init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[self addObserver:self forKeyPath:@"bounds" options:0 context:nil];
|
||||
_colors = [[NSMutableArray alloc] init];
|
||||
_cgColors = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype) initWithCoder:(NSCoder *)aDecoder {
|
||||
self = [super initWithCoder:aDecoder];
|
||||
if (self) {
|
||||
[self addObserver:self forKeyPath:@"bounds" options:0 context:nil];
|
||||
_colors = [[NSMutableArray alloc] init];
|
||||
_cgColors = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype) initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self addObserver:self forKeyPath:@"bounds" options:0 context:nil];
|
||||
_colors = [[NSMutableArray alloc] init];
|
||||
_cgColors = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) setBackgroundLayerWithColors:(NSArray *) colors startPoint:(CGPoint) startPoint {
|
||||
if (colors && [colors count] > 0) {
|
||||
_colors = [[NSMutableArray alloc] initWithArray:colors];
|
||||
[_cgColors removeAllObjects];
|
||||
|
||||
for (UIColor *color in colors) {
|
||||
[_cgColors addObject:(id)color.CGColor];
|
||||
}
|
||||
|
||||
_startPoint = startPoint;
|
||||
|
||||
//[_gradientLayer removeFromSuperlayer];
|
||||
if (!_gradientLayer) {
|
||||
_gradientLayer = [CAGradientLayer layer];
|
||||
}
|
||||
|
||||
_gradientLayer.colors = _cgColors;
|
||||
if (self.translatesAutoresizingMaskIntoConstraints) {
|
||||
|
||||
[_gradientLayer setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
|
||||
}
|
||||
else {
|
||||
|
||||
[_gradientLayer setFrame:self.bounds];
|
||||
}
|
||||
|
||||
|
||||
_gradientLayer.startPoint = _startPoint;
|
||||
|
||||
if (!CGRectEqualToRect(_gradientLayer.frame, CGRectZero)) {
|
||||
[self.layer insertSublayer:_gradientLayer atIndex:0];
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
[_gradientLayer removeFromSuperlayer];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setFrame:(CGRect)frame {
|
||||
[super setFrame:frame];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (_gradientLayer) {
|
||||
[self setBackgroundLayerWithColors:_colors startPoint:_startPoint];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void) setBounds:(CGRect)bounds {
|
||||
[super setBounds:bounds];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (_gradientLayer) {
|
||||
[self setBackgroundLayerWithColors:_colors startPoint:_startPoint];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
if (object == self && [keyPath isEqualToString:@"bounds"]) {
|
||||
if(_gradientLayer) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self setBackgroundLayerWithColors:_colors startPoint:_startPoint];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Whitespace-only changes.
Reference in new issue
Block a user