File tree 2 files changed +22
-18
lines changed
2 files changed +22
-18
lines changed Original file line number Diff line number Diff line change 1
1
/* !
2
- RFDrawImage
3
- RFUI
4
-
5
- Copyright (c) 2014 BB9z
6
- https://github.com/RFUI/Alpha
7
-
8
- The MIT License (MIT)
9
- http://www.opensource.org/licenses/mit-license.php
10
-
11
- BETA
2
+ RFDrawImage
3
+ RFUI
4
+
5
+ Copyright (c) 2014, 2018 BB9z
6
+ https://github.com/RFUI/Alpha
7
+
8
+ The MIT License (MIT)
9
+ http://www.opensource.org/licenses/mit-license.php
12
10
*/
13
11
#import < RFKit/RFRuntime.h>
14
12
15
13
@interface RFDrawImage : NSObject
16
14
17
- + (UIImage *)imageWithSizeColor : (CGSize )imageSize fillColor : (UIColor *)color ;
15
+ + (nonnull UIImage *)imageWithSizeColor : (CGSize )imageSize fillColor : (nonnull UIColor *)color ;
18
16
19
- + (UIImage *)imageWithRoundingCorners : (UIEdgeInsets)cornerRadius
17
+ + (nonnull UIImage *)imageWithRoundingCorners : (UIEdgeInsets)cornerRadius
20
18
size : (CGSize )imageSize
21
- fillColor : (UIColor *)fillColor
22
- strokeColor : (UIColor *)strokeColor
19
+ fillColor : (nonnull UIColor *)fillColor
20
+ strokeColor : (nullable UIColor *)strokeColor
23
21
strokeWidth : (CGFloat )strokeWidth
24
22
boxMargin : (UIEdgeInsets)boxMargin
25
23
resizableCapInsets : (UIEdgeInsets)resizableCapInset
Original file line number Diff line number Diff line change 4
4
@implementation RFDrawImage
5
5
6
6
+ (UIImage *)imageWithSizeColor : (CGSize )imageSize fillColor : (UIColor *)color {
7
+ NSParameterAssert (imageSize.width > 0 && imageSize.height > 0 );
8
+
7
9
UIGraphicsBeginImageContextWithOptions (imageSize, NO , 0 );
8
10
CGContextRef context = UIGraphicsGetCurrentContext ();
9
11
@@ -16,7 +18,8 @@ + (UIImage *)imageWithSizeColor:(CGSize)imageSize fillColor:(UIColor *)color {
16
18
}
17
19
18
20
+ (UIImage *)imageWithRoundingCorners : (UIEdgeInsets)cornerRadius size : (CGSize )imageSize fillColor : (UIColor *)fillColor strokeColor : (UIColor *)strokeColor strokeWidth : (CGFloat )strokeWidth boxMargin : (UIEdgeInsets)margin resizableCapInsets : (UIEdgeInsets)resizableCapInsets scaleFactor : (CGFloat )scaleFactor {
19
-
21
+ NSParameterAssert (imageSize.width > 0 && imageSize.height > 0 );
22
+
20
23
UIGraphicsBeginImageContextWithOptions (imageSize, NO , scaleFactor);
21
24
22
25
CGFloat r_lt = cornerRadius.top ;
@@ -42,12 +45,15 @@ + (UIImage *)imageWithRoundingCorners:(UIEdgeInsets)cornerRadius size:(CGSize)im
42
45
[path addArcWithCenter: c_rt radius: r_rt startAngle: 0 endAngle: M_PI_2 *3 clockwise: NO ];
43
46
44
47
[path closePath ];
48
+ [path addClip ]; // Stop stroke draw outside
45
49
[fillColor setFill ];
46
50
[path fill ];
47
51
48
- [strokeColor setStroke ];
49
- path.lineWidth = strokeWidth;
50
- [path stroke ];
52
+ if (strokeWidth > 0 ) {
53
+ [strokeColor setStroke ];
54
+ path.lineWidth = strokeWidth * 2 ; // Double due to the chip
55
+ [path stroke ];
56
+ }
51
57
52
58
UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
53
59
UIGraphicsEndImageContext ();
You can’t perform that action at this time.
0 commit comments