Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. //
  2. // CircleLayoutPieSlice.m
  3. // dot
  4. //
  5. // Created by LOANER on 3/9/15.
  6. // Copyright (c) 2015 Thomas Degry. All rights reserved.
  7. //
  8.  
  9. #import "CircleLayoutPieSlice.h"
  10.  
  11. @interface CircleLayoutPieSlice()
  12. @property (assign, nonatomic) CGPoint center;
  13. @property (assign, nonatomic) NSInteger index;
  14. @end
  15.  
  16. @implementation CircleLayoutPieSlice
  17. @synthesize path = _path;
  18.  
  19. - (id)initWithFrame:(CGRect)frame path:(UIBezierPath *)path center:(CGPoint)center andIndex:(NSInteger)index {
  20. self = [super initWithFrame:frame];
  21.  
  22. if (self) {
  23. self.center = center;
  24. self.index = index;
  25. self.path = path;
  26.  
  27. self.backgroundColor = [UIColor clearColor];
  28. }
  29.  
  30. return self;
  31. }
  32.  
  33.  
  34. - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  35. if ([self.path containsPoint:point]) {
  36. NSLog(@"contains point for index % li", (long)self.index);
  37. return self;
  38. } else {
  39. NSLog(@"doesn't contain point");
  40. return nil;
  41. }
  42. }
  43.  
  44. - (void)drawRect:(CGRect)rect {
  45. [super drawRect:rect];
  46.  
  47. CGPathRef cgPath = CGPathCreateCopy(self.path.CGPath);
  48.  
  49. CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
  50. CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
  51. CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
  52. UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
  53.  
  54.  
  55.  
  56. CAShapeLayer *triangleMaskLayer = [CAShapeLayer layer];
  57. triangleMaskLayer.fillColor = color.CGColor;
  58. [triangleMaskLayer setPath:cgPath];
  59.  
  60. [self.layer insertSublayer:triangleMaskLayer atIndex:0];
  61. }
  62.  
  63. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement