-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOORadialGradientView.m
42 lines (30 loc) · 1.36 KB
/
OORadialGradientView.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
//
// OORadialGradientView.m
// QuartzGLDemo
//
// Created by Omonayajo Oladapo Adeola on 10/27/15.
// Copyright © 2015 Oonayajo. All rights reserved.
//
#import "OORadialGradientView.h"
@implementation OORadialGradientView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing Code
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw A Gradient from yellow to Orange
NSArray *colors = [NSArray arrayWithObjects:(id)[UIColor yellowColor].CGColor, (id)[UIColor orangeColor].CGColor, nil];
CGColorSpaceRef myColorspace=CGColorSpaceCreateDeviceRGB();
CGGradientRef myGradient = CGGradientCreateWithColors(myColorspace, (CFArrayRef) colors, nil);
double circleWidth = self.viewForBaselineLayout.frame.size.width;
double circleHeight = self.viewForBaselineLayout.frame.size.height;
CGPoint theCenter = CGPointMake(circleWidth/2, circleHeight/2);
// Account for orientation changes
double radius = circleHeight;
if (circleHeight < circleWidth) {
radius = circleWidth;
}
CGGradientDrawingOptions options = kCGGradientDrawsBeforeStartLocation;
CGContextDrawRadialGradient(context, myGradient, theCenter, 0.0, theCenter, radius/1.3, options);
}
@end