diff --git a/RSColorPicker.xcodeproj/project.pbxproj b/RSColorPicker.xcodeproj/project.pbxproj index 4623878..dace81b 100644 --- a/RSColorPicker.xcodeproj/project.pbxproj +++ b/RSColorPicker.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 1FA35E7013F57B2800A6B347 /* RSColorPickerAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FA35E6F13F57B2800A6B347 /* RSColorPickerAppDelegate.m */; }; 1FA35E9913F5A17E00A6B347 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FA35E9813F5A17E00A6B347 /* QuartzCore.framework */; }; 2B12A0DF1792FF46007F2A0A /* TestColorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B12A0DE1792FF46007F2A0A /* TestColorViewController.m */; }; + 2B3D0C1317A4254500D7FA54 /* test.png in Resources */ = {isa = PBXBuildFile; fileRef = 2B3D0C1217A4254500D7FA54 /* test.png */; }; 2B85423116EFC8970047FFBE /* ANImageBitmapRep.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B85420D16EFC8970047FFBE /* ANImageBitmapRep.m */; }; 2B85423216EFC8970047FFBE /* BitmapContextRep.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B85420F16EFC8970047FFBE /* BitmapContextRep.m */; }; 2B85423316EFC8970047FFBE /* NSImage+ANImageBitmapRep.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B85421216EFC8970047FFBE /* NSImage+ANImageBitmapRep.m */; }; @@ -53,6 +54,7 @@ 1FA35E9813F5A17E00A6B347 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 2B12A0DD1792FF46007F2A0A /* TestColorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestColorViewController.h; sourceTree = ""; }; 2B12A0DE1792FF46007F2A0A /* TestColorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestColorViewController.m; sourceTree = ""; }; + 2B3D0C1217A4254500D7FA54 /* test.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = test.png; sourceTree = ""; }; 2B85420C16EFC8970047FFBE /* ANImageBitmapRep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANImageBitmapRep.h; sourceTree = ""; }; 2B85420D16EFC8970047FFBE /* ANImageBitmapRep.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANImageBitmapRep.m; sourceTree = ""; }; 2B85420E16EFC8970047FFBE /* BitmapContextRep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitmapContextRep.h; sourceTree = ""; }; @@ -117,6 +119,7 @@ isa = PBXGroup; children = ( 930D5A7F16DE4D36006C38D4 /* Default-568h@2x.png */, + 2B3D0C1217A4254500D7FA54 /* test.png */, 1FA35E6513F57B2700A6B347 /* RSColorPicker */, 1FA35E5E13F57B2700A6B347 /* Frameworks */, 1FA35E5C13F57B2700A6B347 /* Products */, @@ -307,6 +310,7 @@ files = ( 1FA35E6A13F57B2800A6B347 /* InfoPlist.strings in Resources */, 930D5A8016DE4D36006C38D4 /* Default-568h@2x.png in Resources */, + 2B3D0C1317A4254500D7FA54 /* test.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/RSColorPicker/ColorPickerClasses/BGRSLoupeLayer.m b/RSColorPicker/ColorPickerClasses/BGRSLoupeLayer.m index 9d67ba2..e4a062c 100644 --- a/RSColorPicker/ColorPickerClasses/BGRSLoupeLayer.m +++ b/RSColorPicker/ColorPickerClasses/BGRSLoupeLayer.m @@ -46,7 +46,7 @@ @implementation BGRSLoupeLayer @synthesize loupeCenter, colorPicker; const CGFloat LOUPE_SIZE = 85, SHADOW_SIZE = 6, RIM_THICKNESS = 3.0; -const int NUM_PIXELS = 5, NUM_SKIP = 15; +const int NUM_PIXELS = 5, NUM_SKIP = 1; - (id)init { self = [super init]; diff --git a/RSColorPicker/ColorPickerClasses/RSColorPickerView.h b/RSColorPicker/ColorPickerClasses/RSColorPickerView.h index a1619e2..df4175f 100755 --- a/RSColorPicker/ColorPickerClasses/RSColorPickerView.h +++ b/RSColorPicker/ColorPickerClasses/RSColorPickerView.h @@ -42,6 +42,8 @@ @property (nonatomic, weak) id delegate; +@property (nonatomic) UIImage *customImage; + /** * Get or set the current point (in the color picker's coordinates) * of the selected color. diff --git a/RSColorPicker/ColorPickerClasses/RSColorPickerView.m b/RSColorPicker/ColorPickerClasses/RSColorPickerView.m index e62a3ef..28947d6 100755 --- a/RSColorPicker/ColorPickerClasses/RSColorPickerView.m +++ b/RSColorPicker/ColorPickerClasses/RSColorPickerView.m @@ -190,7 +190,16 @@ - (void)setFrame:(CGRect)frame { - (void)genBitmap { if (!_colorPickerViewFlags.bitmapNeedsUpdate) return; - _rep = [[self class] bitmapForDiameter:_gradientView.bounds.size.width scale:_scale padding:[self paddingDistance] shouldCache:YES]; + BMPoint newSize = BMPointFromSize(RSCGSizeWithScale(_gradientView.bounds.size, _scale)); + + if (_scale <= 0) { + _rep = [[ANImageBitmapRep alloc] initWithSize:newSize]; + } else if (_customImage) { + _rep = [[ANImageBitmapRep alloc] initWithImage:_customImage]; + [_rep setSizeFillingFrame:newSize]; + } else { + _rep = [[self class] bitmapForDiameter:_gradientView.bounds.size.width scale:_scale padding:[self paddingDistance] shouldCache:YES]; + } _colorPickerViewFlags.bitmapNeedsUpdate = NO; _gradientView.image = RSUIImageWithScale([_rep image], _scale); @@ -231,6 +240,14 @@ - (CGPoint)selection { #pragma mark - Setters - +-(void)setCustomImage:(UIImage *)customImage { + if (customImage == _customImage) return; + _customImage = customImage; + + _colorPickerViewFlags.bitmapNeedsUpdate = YES; + [self genBitmap]; +} + - (void)setSelection:(CGPoint)selection { [self updateStateForTouchPoint:selection]; } diff --git a/RSColorPicker/TestColorViewController.m b/RSColorPicker/TestColorViewController.m index e8bbcac..8dfe845 100644 --- a/RSColorPicker/TestColorViewController.m +++ b/RSColorPicker/TestColorViewController.m @@ -31,12 +31,13 @@ - (void)viewDidLoad { // View that displays color picker (needs to be square) _colorPicker = [[RSColorPickerView alloc] initWithFrame:CGRectMake(20.0, 10.0, 280.0, 280.0)]; + + // Specify custom image if needed: + [_colorPicker setCustomImage:[UIImage imageNamed:@"test.png"]]; - // Optionally set and force the picker to only draw a circle -// [_colorPicker setCropToCircle:YES]; // Defaults to NO (you can set BG color) // Set the selection color - useful to present when the user had picked a color previously - [_colorPicker setSelectionColor:[self randomColorOpaque:YES]]; + //[_colorPicker setSelectionColor:[self randomColorOpaque:YES]]; // [_colorPicker setSelectionColor:[UIColor colorWithRed:1 green:0 blue:0.752941 alpha:1.000000]]; // [_colorPicker setSelection:CGPointMake(269, 269)]; diff --git a/test.png b/test.png new file mode 100644 index 0000000..9403962 Binary files /dev/null and b/test.png differ