File tree 1 file changed +15
-15
lines changed
1 file changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -99,21 +99,24 @@ public class Shape: View {
99
99
///An optional variable representing a gradient. If this is non-nil, then the shape will appear to be filled with a gradient.
100
100
public var gradientFill : Gradient ? {
101
101
didSet {
102
- if let fill = gradientFill {
103
- if mask == nil {
104
- let m = Shape ( self )
105
- m. fillColor = black
106
- m. strokeColor = black
107
- mask = m
108
- }
109
- fillColor = nil
110
- shapeLayer. contents = fill. render ( ) ? . cgimage
111
- } else {
112
- let image = UIImage . createWithColor ( UIColor . clearColor ( ) , size: CGSize ( width: 1 , height: 1 ) ) . CGImage
113
- shapeLayer. contents = image
102
+ guard gradientFill != nil else {
103
+ fillColor = clear
114
104
return
115
105
}
106
+ let gim = gradientFill? . render ( ) ? . cgimage
107
+
108
+ //inverts coordinate for graphics context rendering
109
+ var b = bounds
110
+ b. origin. y = self . height - b. origin. y
116
111
112
+ UIGraphicsBeginImageContextWithOptions ( CGSize ( b. size) , false , UIScreen . mainScreen ( ) . scale)
113
+ let context = UIGraphicsGetCurrentContext ( )
114
+
115
+ CGContextDrawTiledImage ( context, CGRect ( b) , gim)
116
+ let uiimage = UIGraphicsGetImageFromCurrentImageContext ( )
117
+ let uicolor = UIColor ( patternImage: uiimage)
118
+ fillColor = Color ( uicolor)
119
+ UIGraphicsEndImageContext ( )
117
120
}
118
121
}
119
122
@@ -179,9 +182,6 @@ public class Shape: View {
179
182
}
180
183
set ( color) {
181
184
shapeLayer. fillColor = color? . CGColor
182
- if color != nil {
183
- gradientFill = nil
184
- }
185
185
}
186
186
}
187
187
You can’t perform that action at this time.
0 commit comments