123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- //
- // PDFColorPickView.m
- // PDFReader
- //
- // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
- //
- // The PDF Reader Sample applications are licensed with a modified BSD license.
- // Please see License for details. This notice may not be removed from this file.
- //
- #import "PDFKTColorPickView.h"
- @implementation PDFKTColorPickView
- {
- NSMutableArray *_colors;
- UIView *_pickColor;
- UIImageView *_pickColorBack;
- }
- @synthesize colorPickDelegate = _colorPickDelegate;
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- _colors = [[NSMutableArray alloc]init];
- [self initColors];
- UIImage *pickImg = [UIImage imageNamed:@"color_view.png"];
- _pickColorBack = [[UIImageView alloc]initWithImage:pickImg];
- _pickColorBack.frame = CGRectMake(0, -70,pickImg.size.width,pickImg.size.height);
- [self addSubview:_pickColorBack];
- _pickColorBack.hidden = YES;
- _pickColor = [[UIView alloc] initWithFrame:CGRectMake(3, 3, 38, 38)];
- _pickColor.backgroundColor = [UIColor greenColor];
- _pickColor.layer.borderColor = [[UIColor grayColor] CGColor];
- _pickColor.layer.borderWidth = 0.7f;
- [_pickColorBack addSubview:_pickColor];
- // _pickColor.hidden = YES;
- }
- return self;
- }
- - (void)dealloc
- {
- _colorPickDelegate = nil;
- [_colors release];
- [_pickColor release];
- [_pickColorBack release];
- [super dealloc];
- }
- - (void)initColors
- {
- UIColor *color = [UIColor colorWithRed:219/255.0 green:3/255.0 blue:1/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:255/255.0 green:127/255.0 blue:0/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:253/255.0 green:135/255.0 blue:106/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:254/255.0 green:218/255.0 blue:28/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:87/255.0 green:218/255.0 blue:20/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:41/255.0 green:109/255.0 blue:209/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:207/255.0 green:27/255.0 blue:255/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:254/255.0 green:28/255.0 blue:133/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
- [_colors addObject:color];
- color = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
- [_colors addObject:color];
- // color = [UIColor colorWithRed:18/255.0 green:17/255.0 blue:77/255.0 alpha:1];
- // [_colors addObject:color];
- // color = [UIColor colorWithRed:78/255.0 green:24/255.0 blue:116/255.0 alpha:1];
- // [_colors addObject:color];
- // color = [UIColor colorWithRed:128/255.0 green:30/255.0 blue:113/255.0 alpha:1];
- // [_colors addObject:color];
- // color = [UIColor colorWithRed:224/255.0 green:43/255.0 blue:95/255.0 alpha:1];
- // [_colors addObject:color];
- // color = [UIColor colorWithRed:87/255.0 green:43/255.0 blue:15/255.0 alpha:1];
- // [_colors addObject:color];
- // color = [UIColor colorWithRed:71/255.0 green:69/255.0 blue:70/255.0 alpha:1];
- // [_colors addObject:color];
- // color = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
- // [_colors addObject:color];
- // color = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
- // [_colors addObject:color];
- }
- - (void)pick:(CGPoint)location show:(BOOL)show
- {
- CGFloat tPosX = location.x;
- CGFloat cellWidth = CGRectGetWidth(self.bounds)/ (CGFloat) [_colors count];
- if (tPosX < 0) tPosX = 0.0;
- NSUInteger index = (NSUInteger)(tPosX / cellWidth);
- if (index > [_colors count] - 1) index = [_colors count] - 1;
- _pickColor.backgroundColor = [_colors objectAtIndex:index];
- CGFloat tPosY = _pickColorBack.center.y;
- if (tPosX > self.bounds.size.width) tPosX = self.bounds.size.width;
- if (tPosX < 0) tPosX = 0;
- _pickColorBack.center = CGPointMake(tPosX, tPosY);
- _pickColorBack.hidden = !show;
- if (_colorPickDelegate && [_colorPickDelegate respondsToSelector:@selector(colorPick:updateColor:)])
- {
- [_colorPickDelegate colorPick:self updateColor:_pickColor.backgroundColor];
- }
- }
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- {
- UITouch *touch = [touches anyObject];
- CGPoint location = [touch locationInView:self];
- [self pick:location show:YES];
- [self.colorPickDelegate colorPickDidBegan:self];
- }
- - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
- {
- // 检查point是否改变
- CGPoint cPoint = [[touches anyObject] locationInView:self];
- CGPoint pPoint = [[touches anyObject] previousLocationInView:self];
- if (CGPointEqualToPoint(cPoint, pPoint)) {
- return;
- }
-
- UITouch *touch = [touches anyObject];
- CGPoint location = [touch locationInView:self];
- [self pick:location show:YES];
- }
- - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- {
- UITouch *touch = [touches anyObject];
- CGPoint location = [touch locationInView:self];
- [self pick:location show:NO];
- [self.colorPickDelegate colorPickDidEnd:self];
- }
- @end
|