Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to set Tint Color for Slider using RGBA #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions MMColorForTrack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// MMColorForTrack.h
//
// Created by Michalis Mavris on 25/03/15.
// Copyright (c) 2015 Miksoft. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface MMColorForTrack : NSObject
+(UIImage*)getTrackImageWithColorR:(NSInteger)r G:(NSInteger)g B:(NSInteger)b A:(NSInteger)a;
@end
59 changes: 59 additions & 0 deletions MMColorForTrack.m
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions NMRangeSlider-Demo/NMDemoTVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>

#import "NMRangeSlider.h"
#import "MMColorForTrack.h"

@interface NMDemoTVC : UITableViewController

Expand Down
4 changes: 4 additions & 0 deletions NMRangeSlider-Demo/NMDemoTVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions NMRangeSlider.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
27D839741AC33B1600B6B6DB /* MMColorForTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MMColorForTrack.m; sourceTree = "<group>"; };
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; };
Expand Down Expand Up @@ -133,6 +136,8 @@
EC36F92715CD0B96009A1A04 = {
isa = PBXGroup;
children = (
27D839731AC33B1500B6B6DB /* MMColorForTrack.h */,
27D839741AC33B1600B6B6DB /* MMColorForTrack.m */,
EC53B5F61993875B00C81C7E /* NMRangeSlider.podspec */,
EC4B675B17F8F1470054842C /* [email protected] */,
EC36F93C15CD0B96009A1A04 /* NMRangeSlider-Demo */,
Expand Down Expand Up @@ -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 */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>67E269A8-B3DD-4CEA-B22B-790BCD9630BE</string>
<key>IDESourceControlProjectName</key>
<string>NMRangeSlider</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>E61B89F65BCF5E1B0B6C39A6E0758DD579FB3D88</key>
<string>https://github.com/mavris/NMRangeSlider.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>NMRangeSlider.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>E61B89F65BCF5E1B0B6C39A6E0758DD579FB3D88</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/mavris/NMRangeSlider.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>E61B89F65BCF5E1B0B6C39A6E0758DD579FB3D88</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>E61B89F65BCF5E1B0B6C39A6E0758DD579FB3D88</string>
<key>IDESourceControlWCCName</key>
<string>NMRangeSlider</string>
</dict>
</array>
</dict>
</plist>