From 8f363912b83edc9499ba3f7f615e78ff8351d3f8 Mon Sep 17 00:00:00 2001 From: Michael Mavris Date: Wed, 25 Mar 2015 21:07:37 +0200 Subject: [PATCH] Added ability to set Tint Color using RGBA --- MMColorForTrack.h | 13 ++++ MMColorForTrack.m | 59 +++++++++++++++++++ NMRangeSlider-Demo/NMDemoTVC.h | 1 + NMRangeSlider-Demo/NMDemoTVC.m | 4 ++ NMRangeSlider.xcodeproj/project.pbxproj | 6 ++ .../xcshareddata/NMRangeSlider.xccheckout | 41 +++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 MMColorForTrack.h create mode 100644 MMColorForTrack.m create mode 100644 NMRangeSlider.xcodeproj/project.xcworkspace/xcshareddata/NMRangeSlider.xccheckout diff --git a/MMColorForTrack.h b/MMColorForTrack.h new file mode 100644 index 0000000..89f51cb --- /dev/null +++ b/MMColorForTrack.h @@ -0,0 +1,13 @@ +// +// MMColorForTrack.h +// +// Created by Michalis Mavris on 25/03/15. +// Copyright (c) 2015 Miksoft. All rights reserved. +// + +#import +#import + +@interface MMColorForTrack : NSObject ++(UIImage*)getTrackImageWithColorR:(NSInteger)r G:(NSInteger)g B:(NSInteger)b A:(NSInteger)a; +@end diff --git a/MMColorForTrack.m b/MMColorForTrack.m new file mode 100644 index 0000000..89438c6 --- /dev/null +++ b/MMColorForTrack.m @@ -0,0 +1,59 @@ +// +// MMColorForTrack.m +// +// Created by Michalis Mavris on 25/03/15. +// Copyright (c) 2015 Miksoft. All rights reserved. +// + +#import "MMColorForTrack.h" + +@implementation MMColorForTrack + ++(UIImage*)getTrackImageWithColorR:(NSInteger)r G:(NSInteger)g B:(NSInteger)b A:(NSInteger)a{ + + +UIImage *newUIImage; + + + int width = 3; + int height = 2; + + char* rgba = (char*)malloc(width*height*4); + int offset=0; + for(int i=0; i < height; ++i) + { + for (int j=0; j < width; j++) + { + rgba[4*offset] = r; + rgba[4*offset+1] = g; + rgba[4*offset+2] = b; + rgba[4*offset+3] = a; + offset ++; + } + } + + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef bitmapContext = CGBitmapContextCreate( + rgba, + width, + height, + 8, // bitsPerComponent + 4*width, // bytesPerRow + colorSpace, + kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big); + + CFRelease(colorSpace); + + CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext); + + free(rgba); + + newUIImage = [UIImage imageWithCGImage:cgImage]; + + + return newUIImage; + + +}; +@end diff --git a/NMRangeSlider-Demo/NMDemoTVC.h b/NMRangeSlider-Demo/NMDemoTVC.h index c853a5d..9e668e0 100644 --- a/NMRangeSlider-Demo/NMDemoTVC.h +++ b/NMRangeSlider-Demo/NMDemoTVC.h @@ -9,6 +9,7 @@ #import #import "NMRangeSlider.h" +#import "MMColorForTrack.h" @interface NMDemoTVC : UITableViewController diff --git a/NMRangeSlider-Demo/NMDemoTVC.m b/NMRangeSlider-Demo/NMDemoTVC.m index d07ad21..3567a17 100644 --- a/NMRangeSlider-Demo/NMDemoTVC.m +++ b/NMRangeSlider-Demo/NMDemoTVC.m @@ -201,6 +201,9 @@ - (void) updateSetValuesSlider - (void) configureSteppedSlider { + //Setting a custom color to the slider track + self.steppedSlider.trackImage=[MMColorForTrack getTrackImageWithColorR:200 G:200 B:0 A:1]; + self.steppedSlider.stepValue = 0.2; } @@ -222,6 +225,7 @@ - (void) configureCrossOverSlider { // you can set a negative minimum range so the lower and upper values can actually // cross over. When they cross over, the track changes color. Custom images can be set. + self.crossOverSlider.minimumRange = -1.0; self.crossOverSlider.upperValue = 0.23; diff --git a/NMRangeSlider.xcodeproj/project.pbxproj b/NMRangeSlider.xcodeproj/project.pbxproj index 154e3ef..e4cd00c 100644 --- a/NMRangeSlider.xcodeproj/project.pbxproj +++ b/NMRangeSlider.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 27D839751AC33B1600B6B6DB /* MMColorForTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D839741AC33B1600B6B6DB /* MMColorForTrack.m */; }; EC36F93715CD0B96009A1A04 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC36F93615CD0B96009A1A04 /* UIKit.framework */; }; EC36F93915CD0B96009A1A04 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC36F93815CD0B96009A1A04 /* Foundation.framework */; }; EC36F93B15CD0B96009A1A04 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC36F93A15CD0B96009A1A04 /* CoreGraphics.framework */; }; @@ -58,6 +59,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 27D839731AC33B1500B6B6DB /* MMColorForTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMColorForTrack.h; sourceTree = ""; }; + 27D839741AC33B1600B6B6DB /* MMColorForTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MMColorForTrack.m; sourceTree = ""; }; EC36F93215CD0B96009A1A04 /* NMRangeSlider.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NMRangeSlider.app; sourceTree = BUILT_PRODUCTS_DIR; }; EC36F93615CD0B96009A1A04 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; EC36F93815CD0B96009A1A04 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -133,6 +136,8 @@ EC36F92715CD0B96009A1A04 = { isa = PBXGroup; children = ( + 27D839731AC33B1500B6B6DB /* MMColorForTrack.h */, + 27D839741AC33B1600B6B6DB /* MMColorForTrack.m */, EC53B5F61993875B00C81C7E /* NMRangeSlider.podspec */, EC4B675B17F8F1470054842C /* Default-568h@2x.png */, EC36F93C15CD0B96009A1A04 /* NMRangeSlider-Demo */, @@ -370,6 +375,7 @@ files = ( EC36F94315CD0B96009A1A04 /* main.m in Sources */, EC36F94715CD0B96009A1A04 /* NMAppDelegate.m in Sources */, + 27D839751AC33B1600B6B6DB /* MMColorForTrack.m in Sources */, EC36F96815CD0D4A009A1A04 /* NMRangeSlider.m in Sources */, EC36F97B15CD0F30009A1A04 /* NMDemoTVC.m in Sources */, ); diff --git a/NMRangeSlider.xcodeproj/project.xcworkspace/xcshareddata/NMRangeSlider.xccheckout b/NMRangeSlider.xcodeproj/project.xcworkspace/xcshareddata/NMRangeSlider.xccheckout new file mode 100644 index 0000000..7d67eca --- /dev/null +++ b/NMRangeSlider.xcodeproj/project.xcworkspace/xcshareddata/NMRangeSlider.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 67E269A8-B3DD-4CEA-B22B-790BCD9630BE + IDESourceControlProjectName + NMRangeSlider + IDESourceControlProjectOriginsDictionary + + E61B89F65BCF5E1B0B6C39A6E0758DD579FB3D88 + https://github.com/mavris/NMRangeSlider.git + + IDESourceControlProjectPath + NMRangeSlider.xcodeproj + IDESourceControlProjectRelativeInstallPathDictionary + + E61B89F65BCF5E1B0B6C39A6E0758DD579FB3D88 + ../.. + + IDESourceControlProjectURL + https://github.com/mavris/NMRangeSlider.git + IDESourceControlProjectVersion + 111 + IDESourceControlProjectWCCIdentifier + E61B89F65BCF5E1B0B6C39A6E0758DD579FB3D88 + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + E61B89F65BCF5E1B0B6C39A6E0758DD579FB3D88 + IDESourceControlWCCName + NMRangeSlider + + + +