LKS_PerspectiveToolbarButtons.m 8.0 KB

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