-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathSAMGradientView.h
More file actions
179 lines (130 loc) · 4.07 KB
/
SAMGradientView.h
File metadata and controls
179 lines (130 loc) · 4.07 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
// SAMGradientView.h
// SAMGradientView
//
// Created by Sam Soffes on 10/27/09.
// Copyright (c) 2009-2013 Sam Soffes. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Availability.h>
/**
The direction the gradient.
*/
typedef enum : NSUInteger {
/** The gradient is verticle. */
SAMGradientViewDirectionVertical,
/** The gradient is horizontal. */
SAMGradientViewDirectionHorizontal,
/** The gradient is build based on gradientStartPoint and gradientEndPoint. */
SAMGradientViewDirectionNone
} SAMGradientViewDirection;
/**
Simple `UIView` wrapper for `CGGradient`.
*/
@interface SAMGradientView : UIView
///---------------------------
/// @name Drawing the Gradient
///---------------------------
/**
An array of `UIColor` objects used to draw the gradient. If the value is `nil`, the `backgroundColor` will be drawn
instead of a gradient.
The default is `nil`.
*/
@property (nonatomic, copy) NSArray *gradientColors;
#ifdef __IPHONE_7_0
/**
An array of `UIColor` objects used to draw the dimmed gradient. If the value is `nil`, `gradientColors` will be
converted to grayscale.
The default is `nil`.
*/
@property (nonatomic, copy) NSArray *dimmedGradientColors;
#endif
/**
Starting point of gradient used only if `gradientDirection` is set to `SAMGradientViewDirectionTwoPoints`
*/
@property (nonatomic, assign) CGPoint gradientStartPoint;
/**
Ending point of gradient used only if `gradientDirection` is set to `SAMGradientViewDirectionTwoPoints`
*/
@property (nonatomic, assign) CGPoint gradientEndPoint;
/**
An optional array of `NSNumber` objects defining the location of each gradient stop.
The gradient stops are specified as values between `0` and `1`. The values must be monotonically
increasing. If `nil`, the stops are spread uniformly across the range. Defaults to `nil`.
*/
@property (nonatomic, copy) NSArray *gradientLocations;
/**
The direction of the gradient.
The default is `SAMGradientViewDirectionVertical`.
*/
@property (nonatomic) SAMGradientViewDirection gradientDirection;
///--------------------------
/// @name Drawing the Borders
///--------------------------
/**
Use thin borders.
1px borders will be drawn instead of 1pt borders. The default is `NO`.
*/
@property (nonatomic) BOOL useThinBorders;
/**
The top border color. The default is `nil`.
@see topInsetColor
*/
@property (nonatomic, strong) UIColor *topBorderColor;
/**
The top inset color. The default is `nil`.
@see topBorderColor
*/
@property (nonatomic, strong) UIColor *topInsetColor;
/**
The right border color. The default is `nil`.
@see rightInsetColor
*/
@property (nonatomic, strong) UIColor *rightBorderColor;
/**
The right inset color. The default is `nil`.
@see rightBorderColor
*/
@property (nonatomic, strong) UIColor *rightInsetColor;
/**
The bottom border color. The default is `nil`.
@see bottomInsetColor
*/
@property (nonatomic, strong) UIColor *bottomBorderColor;
/**
The bottom inset color. The default is `nil`.
@see bottomBorderColor
*/
@property (nonatomic, strong) UIColor *bottomInsetColor;
/**
The left border color. The default is `nil`.
@see leftInsetColor
*/
@property (nonatomic, strong) UIColor *leftBorderColor;
/**
The left inset color. The default is `nil`.
@see leftBorderColor
*/
@property (nonatomic, strong) UIColor *leftInsetColor;
@end
///-------------------------
/// @name Creating Gradients
///-------------------------
/**
Create a CGGradient with an array of UIColors.
@return CGGradientRef
*/
extern CGGradientRef SAMGradientCreateWithColors(NSArray *colors) CF_RETURNS_RETAINED;
/**
Create a CGGradient with an array of UIColors and NSNumbers for locations.
@return CGGradientRef
*/
extern CGGradientRef SAMGradientCreateWithColorsAndLocations(NSArray *colors, NSArray *locations) CF_RETURNS_RETAINED;
///------------------------
/// @name Drawing Gradients
///------------------------
/**
Draw a CGGraident into a rect. This handles cliping the gradient for you.
*/
extern void SAMDrawGradientInRect(CGContextRef context, CGGradientRef gradient, CGRect rect);