LKS_PerspectiveToolbarButtons.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // LKS_PerspectiveToolbarButtons.m
  3. // qmuidemo
  4. //
  5. // Created by Li Kai on 2018/12/20.
  6. // Copyright © 2018 QMUI Team. All rights reserved.
  7. //
  8. #import "LKS_PerspectiveToolbarButtons.h"
  9. static CGFloat const kConerRadius = 6;
  10. @implementation LKS_PerspectiveToolbarCloseButton
  11. - (instancetype)initWithFrame:(CGRect)frame {
  12. if (self = [super initWithFrame:frame]) {
  13. [self setImage:[self _image] forState:UIControlStateNormal];
  14. self.backgroundColor = [UIColor blackColor];
  15. self.layer.cornerRadius = kConerRadius;
  16. }
  17. return self;
  18. }
  19. - (UIImage *)_image {
  20. CGFloat width = 13;
  21. UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, width), NO, 0);
  22. CGContextRef context = UIGraphicsGetCurrentContext();
  23. UIBezierPath *path = [UIBezierPath bezierPath];
  24. [path moveToPoint:CGPointMake(0, 0)];
  25. [path addLineToPoint:CGPointMake(width, width)];
  26. [path moveToPoint:CGPointMake(width, 0)];
  27. [path addLineToPoint:CGPointMake(0, width)];
  28. CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
  29. [path setLineWidth:1];
  30. [path stroke];
  31. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  32. UIGraphicsEndImageContext();
  33. return image;
  34. }
  35. @end
  36. @implementation LKS_PerspectiveToolbarDimensionButtonsView
  37. - (instancetype)initWithFrame:(CGRect)frame {
  38. if (self = [super initWithFrame:frame]) {
  39. self.backgroundColor = [UIColor blackColor];
  40. self.layer.cornerRadius = kConerRadius;
  41. self.clipsToBounds = YES;
  42. _button2D = [UIButton new];
  43. [self.button2D setImage:[self _image2D] forState:UIControlStateNormal];
  44. [self addSubview:self.button2D];
  45. _button3D = [UIButton new];
  46. [self.button3D setImage:[self _image3D] forState:UIControlStateNormal];
  47. [self addSubview:self.button3D];
  48. }
  49. return self;
  50. }
  51. - (void)layoutSubviews {
  52. [super layoutSubviews];
  53. CGFloat halfWidth = self.bounds.size.width / 2.0;
  54. CGFloat height = self.bounds.size.height;
  55. self.button2D.frame = CGRectMake(0, 0, halfWidth, height);
  56. self.button3D.frame = CGRectMake(halfWidth, 0, halfWidth, height);
  57. }
  58. - (UIImage *)_image2D {
  59. CGFloat width = 16;
  60. UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, width), NO, 0);
  61. CGContextRef context = UIGraphicsGetCurrentContext();
  62. UIBezierPath *path = [UIBezierPath bezierPath];
  63. [path moveToPoint:CGPointMake(1, 1)];
  64. [path addLineToPoint:CGPointMake(width - 1, 1)];
  65. [path addLineToPoint:CGPointMake(width - 1, width - 1)];
  66. [path addLineToPoint:CGPointMake(1, width - 1)];
  67. [path closePath];
  68. CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
  69. [path setLineWidth:1];
  70. [path stroke];
  71. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  72. UIGraphicsEndImageContext();
  73. return image;
  74. }
  75. - (UIImage *)_image3D {
  76. CGFloat width = 16;
  77. CGFloat height = 18;
  78. UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, 0);
  79. CGContextRef context = UIGraphicsGetCurrentContext();
  80. UIBezierPath *path = [UIBezierPath bezierPath];
  81. [path moveToPoint:CGPointMake(width / 2.0, 1)];
  82. [path addLineToPoint:CGPointMake(width - 1, 4)];
  83. [path addLineToPoint:CGPointMake(width / 2.0, 7)];
  84. [path addLineToPoint:CGPointMake(1, 4)];
  85. [path closePath];
  86. [path moveToPoint:CGPointMake(1, 4)];
  87. [path addLineToPoint:CGPointMake(1, height - 4)];
  88. [path addLineToPoint:CGPointMake(width / 2.0, height - 1)];
  89. [path addLineToPoint:CGPointMake(width - 1, height - 4)];
  90. [path addLineToPoint:CGPointMake(width - 1, 4)];
  91. [path moveToPoint:CGPointMake(width / 2.0, 7)];
  92. [path addLineToPoint:CGPointMake(width / 2.0, height - 1)];
  93. CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
  94. [path setLineWidth:1];
  95. [path stroke];
  96. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  97. UIGraphicsEndImageContext();
  98. return image;
  99. }
  100. @end
  101. @implementation LKS_PerspectiveToolbarLayoutButtonsView
  102. - (instancetype)initWithFrame:(CGRect)frame {
  103. if (self = [super initWithFrame:frame]) {
  104. self.backgroundColor = [UIColor blackColor];
  105. self.layer.cornerRadius = kConerRadius;
  106. self.clipsToBounds = YES;
  107. _verticalLayoutButton = [UIButton new];
  108. [self.verticalLayoutButton setImage:[self _imageVertical] forState:UIControlStateNormal];
  109. [self addSubview:self.verticalLayoutButton];
  110. _horizontalLayoutButton = [UIButton new];
  111. [self.horizontalLayoutButton setImage:[self _imageHorizontal] forState:UIControlStateNormal];
  112. [self addSubview:self.horizontalLayoutButton];
  113. }
  114. return self;
  115. }
  116. - (void)layoutSubviews {
  117. [super layoutSubviews];
  118. CGFloat halfWidth = self.bounds.size.width / 2.0;
  119. CGFloat height = self.bounds.size.height;
  120. self.verticalLayoutButton.frame = CGRectMake(0, 0, halfWidth, height);
  121. self.horizontalLayoutButton.frame = CGRectMake(halfWidth, 0, halfWidth, height);
  122. }
  123. - (UIImage *)_imageHorizontal {
  124. CGFloat width = 19;
  125. CGFloat height = 17;
  126. UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, 0);
  127. CGContextRef context = UIGraphicsGetCurrentContext();
  128. CGRect outRect = CGRectMake(1, 1, width - 2, height - 2);
  129. UIBezierPath *path = [UIBezierPath bezierPathWithRect:outRect];
  130. CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
  131. [path setLineWidth:1];
  132. [path stroke];
  133. path = [UIBezierPath bezierPathWithRect:CGRectMake(CGRectGetMinX(outRect) + 3, CGRectGetMinY(outRect) + 3, 2, CGRectGetHeight(outRect) - 6)];
  134. CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
  135. [path fill];
  136. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  137. UIGraphicsEndImageContext();
  138. return image;
  139. }
  140. - (UIImage *)_imageVertical {
  141. CGFloat width = 19;
  142. CGFloat height = 17;
  143. UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, 0);
  144. CGContextRef context = UIGraphicsGetCurrentContext();
  145. CGRect outRect = CGRectMake(1, 1, width - 2, height - 2);
  146. UIBezierPath *path = [UIBezierPath bezierPathWithRect:outRect];
  147. CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
  148. [path setLineWidth:1];
  149. [path stroke];
  150. path = [UIBezierPath bezierPathWithRect:CGRectMake(CGRectGetMinX(outRect) + 3, CGRectGetMaxY(outRect) - 5, CGRectGetWidth(outRect) - 6, 2)];
  151. CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
  152. [path fill];
  153. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  154. UIGraphicsEndImageContext();
  155. return image;
  156. }
  157. @end
  158. @implementation LKS_PerspectiveToolbarPropertyButton
  159. - (instancetype)initWithFrame:(CGRect)frame {
  160. if (self = [super initWithFrame:frame]) {
  161. [self setImage:[self _image] forState:UIControlStateNormal];
  162. self.backgroundColor = [UIColor blackColor];
  163. self.layer.cornerRadius = kConerRadius;
  164. }
  165. return self;
  166. }
  167. - (UIImage *)_image {
  168. CGFloat width = 20;
  169. UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, width), NO, 0);
  170. CGContextRef context = UIGraphicsGetCurrentContext();
  171. CGFloat ovalRadius = 3;
  172. UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(width / 2.0 - ovalRadius / 2.0, 4, ovalRadius, ovalRadius)];
  173. CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
  174. [path fill];
  175. path = [UIBezierPath bezierPath];
  176. [path moveToPoint:CGPointMake(width / 2.0, 9)];
  177. [path addLineToPoint:CGPointMake(width / 2.0, width - 4)];
  178. [path setLineWidth:2];
  179. CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
  180. [path stroke];
  181. path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(1, 1, width - 2, width - 2)];
  182. [path setLineWidth:1];
  183. [path stroke];
  184. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  185. UIGraphicsEndImageContext();
  186. return image;
  187. }
  188. @end