Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CircleLayoutPieSlice.m
- // dot
- //
- // Created by LOANER on 3/9/15.
- // Copyright (c) 2015 Thomas Degry. All rights reserved.
- //
- #import "CircleLayoutPieSlice.h"
- @interface CircleLayoutPieSlice()
- @property (assign, nonatomic) CGPoint center;
- @property (assign, nonatomic) NSInteger index;
- @end
- @implementation CircleLayoutPieSlice
- @synthesize path = _path;
- - (id)initWithFrame:(CGRect)frame path:(UIBezierPath *)path center:(CGPoint)center andIndex:(NSInteger)index {
- self = [super initWithFrame:frame];
- if (self) {
- self.center = center;
- self.index = index;
- self.path = path;
- self.backgroundColor = [UIColor clearColor];
- }
- return self;
- }
- - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
- if ([self.path containsPoint:point]) {
- NSLog(@"contains point for index % li", (long)self.index);
- return self;
- } else {
- NSLog(@"doesn't contain point");
- return nil;
- }
- }
- - (void)drawRect:(CGRect)rect {
- [super drawRect:rect];
- CGPathRef cgPath = CGPathCreateCopy(self.path.CGPath);
- CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
- CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
- CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
- UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
- CAShapeLayer *triangleMaskLayer = [CAShapeLayer layer];
- triangleMaskLayer.fillColor = color.CGColor;
- [triangleMaskLayer setPath:cgPath];
- [self.layer insertSublayer:triangleMaskLayer atIndex:0];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement