TOSettingsKeypadImage.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // TOSettingsKeypadImage.m
  3. // TOPasscodeViewControllerExample
  4. //
  5. // Created by Tim Oliver on 6/20/17.
  6. // Copyright © 2017 Timothy Oliver. All rights reserved.
  7. //
  8. #import "TOSettingsKeypadImage.h"
  9. #define TOP_LEFT(X, Y) CGPointMake(rect.origin.x + X * limitedRadius, rect.origin.y + Y * limitedRadius)
  10. #define TOP_RIGHT(X, Y) CGPointMake(rect.origin.x + rect.size.width - X * limitedRadius, rect.origin.y + Y * limitedRadius)
  11. #define BOTTOM_RIGHT(X, Y) CGPointMake(rect.origin.x + rect.size.width - X * limitedRadius, rect.origin.y + rect.size.height - Y * limitedRadius)
  12. #define BOTTOM_LEFT(X, Y) CGPointMake(rect.origin.x + X * limitedRadius, rect.origin.y + rect.size.height - Y * limitedRadius)
  13. @implementation TOSettingsKeypadImage
  14. + (UIImage *)buttonImageWithCornerRadius:(CGFloat)radius
  15. foregroundColor:(UIColor *)foregroundColor
  16. edgeColor:(UIColor *)edgeColor
  17. edgeThickness:(CGFloat)thickness
  18. {
  19. CGFloat width = (radius * 2.0f) + 1.0f;
  20. CGFloat height = width + thickness;
  21. CGRect frame = (CGRect){CGPointZero, {width, height}};
  22. UIImage *image = nil;
  23. UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0.0f);
  24. {
  25. CGContextRef context = UIGraphicsGetCurrentContext();
  26. NSShadow* shadow = [[NSShadow alloc] init];
  27. shadow.shadowColor = edgeColor;
  28. shadow.shadowOffset = CGSizeMake(0, thickness);
  29. shadow.shadowBlurRadius = 0;
  30. CGRect buttonFrame = frame;
  31. buttonFrame.size.height -= thickness;
  32. CGContextSaveGState(context);
  33. {
  34. CGContextSetShadowWithColor(context, shadow.shadowOffset, shadow.shadowBlurRadius, [shadow.shadowColor CGColor]);
  35. UIBezierPath *buttonPath = [[self class] bezierPathWithContinuousRoundedRect:buttonFrame cornerRadius:radius];//bezierPathWithRoundedRect:buttonFrame cornerRadius:radius];
  36. [foregroundColor setFill];
  37. [buttonPath fill];
  38. }
  39. CGContextRestoreGState(context);
  40. image = UIGraphicsGetImageFromCurrentImageContext();
  41. }
  42. UIGraphicsEndImageContext();
  43. UIEdgeInsets insets = UIEdgeInsetsMake(radius, radius, radius + thickness, radius);
  44. image = [image resizableImageWithCapInsets:insets];
  45. return image;
  46. }
  47. + (UIImage *)deleteIcon
  48. {
  49. UIImage *image = nil;
  50. CGRect frame = CGRectMake(0, 0, 40.0f, 21.0f);
  51. UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0.0f);
  52. {
  53. //// DeleteIcon
  54. {
  55. //// Border Drawing
  56. UIBezierPath* borderPath = [UIBezierPath bezierPath];
  57. [borderPath moveToPoint: CGPointMake(25.73, 1.5)];
  58. [borderPath addLineToPoint: CGPointMake(25.9, 1.53)];
  59. [borderPath addCurveToPoint: CGPointMake(28.34, 3.46) controlPoint1: CGPointMake(27.03, 1.86) controlPoint2: CGPointMake(27.93, 2.56)];
  60. [borderPath addCurveToPoint: CGPointMake(28.67, 6.56) controlPoint1: CGPointMake(28.67, 4.28) controlPoint2: CGPointMake(28.67, 5.04)];
  61. [borderPath addLineToPoint: CGPointMake(28.64, 14.23)];
  62. [borderPath addCurveToPoint: CGPointMake(28.35, 17.05) controlPoint1: CGPointMake(28.64, 15.76) controlPoint2: CGPointMake(28.64, 16.37)];
  63. [borderPath addLineToPoint: CGPointMake(28.31, 17.19)];
  64. [borderPath addCurveToPoint: CGPointMake(25.86, 19.11) controlPoint1: CGPointMake(27.89, 18.08) controlPoint2: CGPointMake(27, 18.79)];
  65. [borderPath addCurveToPoint: CGPointMake(21.4, 19.37) controlPoint1: CGPointMake(24.82, 19.37) controlPoint2: CGPointMake(23.34, 19.37)];
  66. [borderPath addLineToPoint: CGPointMake(11.51, 19.37)];
  67. [borderPath addCurveToPoint: CGPointMake(9.9, 19.07) controlPoint1: CGPointMake(11.51, 19.37) controlPoint2: CGPointMake(10.41, 19.3)];
  68. [borderPath addCurveToPoint: CGPointMake(7.38, 17.06) controlPoint1: CGPointMake(9.09, 18.68) controlPoint2: CGPointMake(8.52, 18.14)];
  69. [borderPath addLineToPoint: CGPointMake(3.92, 13.81)];
  70. [borderPath addCurveToPoint: CGPointMake(1.87, 11.55) controlPoint1: CGPointMake(2.78, 12.73) controlPoint2: CGPointMake(2.21, 12.19)];
  71. [borderPath addLineToPoint: CGPointMake(1.79, 11.43)];
  72. [borderPath addCurveToPoint: CGPointMake(1.82, 9.06) controlPoint1: CGPointMake(1.36, 10.57) controlPoint2: CGPointMake(1.4, 9.92)];
  73. [borderPath addCurveToPoint: CGPointMake(3.96, 6.68) controlPoint1: CGPointMake(2.25, 8.29) controlPoint2: CGPointMake(2.82, 7.76)];
  74. [borderPath addLineToPoint: CGPointMake(7.21, 3.61)];
  75. [borderPath addCurveToPoint: CGPointMake(9.61, 1.67) controlPoint1: CGPointMake(8.35, 2.54) controlPoint2: CGPointMake(8.92, 2)];
  76. [borderPath addLineToPoint: CGPointMake(9.73, 1.6)];
  77. [borderPath addCurveToPoint: CGPointMake(11.41, 1.31) controlPoint1: CGPointMake(10.26, 1.37) controlPoint2: CGPointMake(10.84, 1.27)];
  78. [borderPath addLineToPoint: CGPointMake(21.44, 1.27)];
  79. [borderPath addCurveToPoint: CGPointMake(25.73, 1.5) controlPoint1: CGPointMake(23.38, 1.27) controlPoint2: CGPointMake(24.85, 1.27)];
  80. [borderPath closePath];
  81. [UIColor.blackColor setStroke];
  82. borderPath.lineWidth = 2.5;
  83. [borderPath stroke];
  84. //// Cross Drawing
  85. UIBezierPath* crossPath = [UIBezierPath bezierPath];
  86. [crossPath moveToPoint: CGPointMake(15.22, 5.9)];
  87. [crossPath addCurveToPoint: CGPointMake(15.21, 5.88) controlPoint1: CGPointMake(15.27, 5.95) controlPoint2: CGPointMake(15.21, 5.88)];
  88. [crossPath addLineToPoint: CGPointMake(15.22, 5.9)];
  89. [crossPath closePath];
  90. [crossPath moveToPoint: CGPointMake(16.18, 10.28)];
  91. [crossPath addCurveToPoint: CGPointMake(16.19, 10.26) controlPoint1: CGPointMake(16.22, 10.29) controlPoint2: CGPointMake(16.2, 10.28)];
  92. [crossPath addLineToPoint: CGPointMake(16.18, 10.28)];
  93. [crossPath closePath];
  94. [crossPath moveToPoint: CGPointMake(14.52, 5.35)];
  95. [crossPath addCurveToPoint: CGPointMake(15.21, 5.88) controlPoint1: CGPointMake(14.75, 5.46) controlPoint2: CGPointMake(14.93, 5.62)];
  96. [crossPath addCurveToPoint: CGPointMake(15.38, 6.05) controlPoint1: CGPointMake(15.26, 5.94) controlPoint2: CGPointMake(15.32, 5.99)];
  97. [crossPath addCurveToPoint: CGPointMake(15.43, 6.09) controlPoint1: CGPointMake(15.42, 6.09) controlPoint2: CGPointMake(15.43, 6.09)];
  98. [crossPath addCurveToPoint: CGPointMake(15.38, 6.05) controlPoint1: CGPointMake(15.21, 5.88) controlPoint2: CGPointMake(15.27, 5.95)];
  99. [crossPath addCurveToPoint: CGPointMake(17.97, 8.55) controlPoint1: CGPointMake(15.94, 6.59) controlPoint2: CGPointMake(17.66, 8.25)];
  100. [crossPath addCurveToPoint: CGPointMake(17.97, 8.55) controlPoint1: CGPointMake(17.91, 8.61) controlPoint2: CGPointMake(17.94, 8.58)];
  101. [crossPath addCurveToPoint: CGPointMake(21.36, 5.39) controlPoint1: CGPointMake(20.95, 5.68) controlPoint2: CGPointMake(21.14, 5.5)];
  102. [crossPath addCurveToPoint: CGPointMake(22.67, 5.58) controlPoint1: CGPointMake(21.83, 5.17) controlPoint2: CGPointMake(22.34, 5.26)];
  103. [crossPath addCurveToPoint: CGPointMake(22.98, 6.89) controlPoint1: CGPointMake(23.09, 5.99) controlPoint2: CGPointMake(23.18, 6.47)];
  104. [crossPath addCurveToPoint: CGPointMake(22.28, 7.68) controlPoint1: CGPointMake(22.84, 7.14) controlPoint2: CGPointMake(22.65, 7.32)];
  105. [crossPath addCurveToPoint: CGPointMake(19.68, 10.19) controlPoint1: CGPointMake(22.28, 7.68) controlPoint2: CGPointMake(20.88, 9.03)];
  106. [crossPath addCurveToPoint: CGPointMake(22.97, 13.47) controlPoint1: CGPointMake(22.66, 13.06) controlPoint2: CGPointMake(22.85, 13.25)];
  107. [crossPath addCurveToPoint: CGPointMake(22.76, 14.79) controlPoint1: CGPointMake(23.21, 13.95) controlPoint2: CGPointMake(23.11, 14.46)];
  108. [crossPath addCurveToPoint: CGPointMake(21.35, 15.1) controlPoint1: CGPointMake(22.33, 15.22) controlPoint2: CGPointMake(21.8, 15.31)];
  109. [crossPath addCurveToPoint: CGPointMake(20.48, 14.4) controlPoint1: CGPointMake(21.07, 14.97) controlPoint2: CGPointMake(20.87, 14.78)];
  110. [crossPath addCurveToPoint: CGPointMake(17.89, 11.91) controlPoint1: CGPointMake(20.48, 14.4) controlPoint2: CGPointMake(19.08, 13.05)];
  111. [crossPath addCurveToPoint: CGPointMake(14.5, 15.06) controlPoint1: CGPointMake(14.91, 14.78) controlPoint2: CGPointMake(14.73, 14.95)];
  112. [crossPath addCurveToPoint: CGPointMake(13.2, 14.87) controlPoint1: CGPointMake(14.04, 15.28) controlPoint2: CGPointMake(13.53, 15.19)];
  113. [crossPath addCurveToPoint: CGPointMake(12.89, 13.57) controlPoint1: CGPointMake(12.78, 14.47) controlPoint2: CGPointMake(12.69, 13.98)];
  114. [crossPath addCurveToPoint: CGPointMake(13.42, 12.93) controlPoint1: CGPointMake(13, 13.35) controlPoint2: CGPointMake(13.15, 13.19)];
  115. [crossPath addCurveToPoint: CGPointMake(13.59, 12.77) controlPoint1: CGPointMake(13.47, 12.88) controlPoint2: CGPointMake(13.53, 12.83)];
  116. [crossPath addCurveToPoint: CGPointMake(16.19, 10.26) controlPoint1: CGPointMake(14.12, 12.25) controlPoint2: CGPointMake(15.78, 10.66)];
  117. [crossPath addCurveToPoint: CGPointMake(12.89, 6.98) controlPoint1: CGPointMake(13.21, 7.39) controlPoint2: CGPointMake(13.01, 7.2)];
  118. [crossPath addCurveToPoint: CGPointMake(12.77, 6.63) controlPoint1: CGPointMake(12.82, 6.84) controlPoint2: CGPointMake(12.79, 6.73)];
  119. [crossPath addCurveToPoint: CGPointMake(13.1, 5.66) controlPoint1: CGPointMake(12.72, 6.28) controlPoint2: CGPointMake(12.83, 5.92)];
  120. [crossPath addCurveToPoint: CGPointMake(14.52, 5.35) controlPoint1: CGPointMake(13.54, 5.24) controlPoint2: CGPointMake(14.07, 5.15)];
  121. [crossPath closePath];
  122. [UIColor.blackColor setFill];
  123. [crossPath fill];
  124. }
  125. image = UIGraphicsGetImageFromCurrentImageContext();
  126. }
  127. UIGraphicsEndImageContext();
  128. return [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
  129. }
  130. /**
  131. Creates a bezier path with the iOS 7 squircle shape.
  132. A HUGE thanks to the folks at PaintCode for open-sourcing this
  133. https://www.paintcodeapp.com/news/code-for-ios-7-rounded-rectangles
  134. */
  135. + (UIBezierPath *)bezierPathWithContinuousRoundedRect:(CGRect)rect cornerRadius:(CGFloat)radius
  136. {
  137. UIBezierPath* path = UIBezierPath.bezierPath;
  138. CGFloat limit = MIN(rect.size.width, rect.size.height) / 2 / 1.52866483;
  139. CGFloat limitedRadius = MIN(radius, limit);
  140. [path moveToPoint: TOP_LEFT(1.52866483, 0.00000000)];
  141. [path addLineToPoint: TOP_RIGHT(1.52866471, 0.00000000)];
  142. [path addCurveToPoint: TOP_RIGHT(0.66993427, 0.06549600) controlPoint1: TOP_RIGHT(1.08849323, 0.00000000) controlPoint2: TOP_RIGHT(0.86840689, 0.00000000)];
  143. [path addLineToPoint: TOP_RIGHT(0.63149399, 0.07491100)];
  144. [path addCurveToPoint: TOP_RIGHT(0.07491176, 0.63149399) controlPoint1: TOP_RIGHT(0.37282392, 0.16905899) controlPoint2: TOP_RIGHT(0.16906013, 0.37282401)];
  145. [path addCurveToPoint: TOP_RIGHT(0.00000000, 1.52866483) controlPoint1: TOP_RIGHT(0.00000000, 0.86840701) controlPoint2: TOP_RIGHT(0.00000000, 1.08849299)];
  146. [path addLineToPoint: BOTTOM_RIGHT(0.00000000, 1.52866471)];
  147. [path addCurveToPoint: BOTTOM_RIGHT(0.06549569, 0.66993493) controlPoint1: BOTTOM_RIGHT(0.00000000, 1.08849323) controlPoint2: BOTTOM_RIGHT(0.00000000, 0.86840689)];
  148. [path addLineToPoint: BOTTOM_RIGHT(0.07491111, 0.63149399)];
  149. [path addCurveToPoint: BOTTOM_RIGHT(0.63149399, 0.07491111) controlPoint1: BOTTOM_RIGHT(0.16905883, 0.37282392) controlPoint2: BOTTOM_RIGHT(0.37282392, 0.16905883)];
  150. [path addCurveToPoint: BOTTOM_RIGHT(1.52866471, 0.00000000) controlPoint1: BOTTOM_RIGHT(0.86840689, 0.00000000) controlPoint2: BOTTOM_RIGHT(1.08849323, 0.00000000)];
  151. [path addLineToPoint: BOTTOM_LEFT(1.52866483, 0.00000000)];
  152. [path addCurveToPoint: BOTTOM_LEFT(0.66993397, 0.06549569) controlPoint1: BOTTOM_LEFT(1.08849299, 0.00000000) controlPoint2: BOTTOM_LEFT(0.86840701, 0.00000000)];
  153. [path addLineToPoint: BOTTOM_LEFT(0.63149399, 0.07491111)];
  154. [path addCurveToPoint: BOTTOM_LEFT(0.07491100, 0.63149399) controlPoint1: BOTTOM_LEFT(0.37282401, 0.16905883) controlPoint2: BOTTOM_LEFT(0.16906001, 0.37282392)];
  155. [path addCurveToPoint: BOTTOM_LEFT(0.00000000, 1.52866471) controlPoint1: BOTTOM_LEFT(0.00000000, 0.86840689) controlPoint2: BOTTOM_LEFT(0.00000000, 1.08849323)];
  156. [path addLineToPoint: TOP_LEFT(0.00000000, 1.52866483)];
  157. [path addCurveToPoint: TOP_LEFT(0.06549600, 0.66993397) controlPoint1: TOP_LEFT(0.00000000, 1.08849299) controlPoint2: TOP_LEFT(0.00000000, 0.86840701)];
  158. [path addLineToPoint: TOP_LEFT(0.07491100, 0.63149399)];
  159. [path addCurveToPoint: TOP_LEFT(0.63149399, 0.07491100) controlPoint1: TOP_LEFT(0.16906001, 0.37282401) controlPoint2: TOP_LEFT(0.37282401, 0.16906001)];
  160. [path addCurveToPoint: TOP_LEFT(1.52866483, 0.00000000) controlPoint1: TOP_LEFT(0.86840701, 0.00000000) controlPoint2: TOP_LEFT(1.08849299, 0.00000000)];
  161. [path closePath];
  162. return path;
  163. }
  164. @end