mrs- / hexcolors Goto Github PK
View Code? Open in Web Editor NEWHexColors is an extension for UIColor and NSColor to support for creating colors from a hex strings
License: MIT License
HexColors is an extension for UIColor and NSColor to support for creating colors from a hex strings
License: MIT License
This method name is a common-enough choice that it conflicts with other pods (e.g. MDCSwipeToChoose), causing undefined behaviour and breaking various functionality. Please rename it to something unique so these issues can be avoided.
(This could well apply to other methods, but it was this one in particular that caused me problems.)
Possible to add bridging headers to the latest version such that it can be used in objective-c? Would be nice to take advantage of the latest APIs when still stuck with large projects in objective c.
I don't know if you are controlling the podspec as well on cocoapods, but would be great if you could make it compatible with OSX as well!
To be compatible with other libraries, e.g. APUtils, colorWithHexString should also take a string of length 9 which includes an 8-bit alpha as the first octet.
Hello, Marius Landwehr
I think it's very useful to add a global cache for HexColors, like NSColor or UIColor, and I add it myself.
What do you think about it ?
Best regards!
Since the API changed with the new version, according to semantic versioning, shouldn't the version number be bumped to 3.0.0? By not changing the major version, people who were depending on the old cocoa pod have had the pod automatically updated to the next minor version (2.3.0) and their projects are breaking. (This includes me).
Since the update to the APIs have broken my project, can we get at change log that explains the API changes for 2.3.0 and what I need to be looking at to migrate to the new version?
Thanks
$ carthage update --platform iOS
yields:
*** Fetching HexColors
...
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:30:14: warning: unused variable 'nilColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:37:14: warning: unused variable 'falseColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:44:14: warning: unused variable 'whiteColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:45:14: warning: unused variable 'whiteHexColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:52:14: warning: unused variable 'whiteColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:53:14: warning: unused variable 'whiteHexColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:60:14: warning: unused variable 'whiteColorAlpha' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:61:14: warning: unused variable 'whiteHexColorAlpha' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:68:14: warning: unused variable 'greyColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:69:14: warning: unused variable 'rgbColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:30:14: warning: unused variable 'nilColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:37:14: warning: unused variable 'falseColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:44:14: warning: unused variable 'whiteColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:45:14: warning: unused variable 'whiteHexColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:52:14: warning: unused variable 'whiteColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:53:14: warning: unused variable 'whiteHexColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:60:14: warning: unused variable 'whiteColorAlpha' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:61:14: warning: unused variable 'whiteHexColorAlpha' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:68:14: warning: unused variable 'greyColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:69:14: warning: unused variable 'rgbColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:30:14: warning: unused variable 'nilColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:37:14: warning: unused variable 'falseColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:44:14: warning: unused variable 'whiteColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:45:14: warning: unused variable 'whiteHexColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:52:14: warning: unused variable 'whiteColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:53:14: warning: unused variable 'whiteHexColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:60:14: warning: unused variable 'whiteColorAlpha' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:61:14: warning: unused variable 'whiteHexColorAlpha' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:68:14: warning: unused variable 'greyColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:69:14: warning: unused variable 'rgbColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:30:14: warning: unused variable 'nilColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:37:14: warning: unused variable 'falseColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:44:14: warning: unused variable 'whiteColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:45:14: warning: unused variable 'whiteHexColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:52:14: warning: unused variable 'whiteColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:53:14: warning: unused variable 'whiteHexColor' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:60:14: warning: unused variable 'whiteColorAlpha' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:61:14: warning: unused variable 'whiteHexColorAlpha' [-Wunused-variable]
project-dir/Carthage/Checkouts/HexColors/HexColorsTests/HexColorsTests.m:68:14: warning: unused variable 'greyColor' [-Wunused-variable]
I am getting a new warning when moved to Xcode 9.1 beta 2
Swift Compiler Warning
HexColors.swift:74:21: 'characters' is deprecated: Please use String or Substring directly
I getting this type of error in xcode 7.3 and Swift version 2.3
I want to rewrite the complete library in swift for easier support in swift only projects. For this I will bump this up to version 4.0.0 and it can be API breaking. It will support iOS, tvOS, watchOS and OS X and it will be complete documented.
macOS: 10.15.6 (19G2021)
Xcode: 11.6 (11E708)
Carthage: 0.35.0
github "mRs-/HexColors" == 4.0.0
Using HexColors in both Swift and Objective-C
Failed to read file or folder at project-path/Carthage/Build/iOS/HexColors.franework: Error Domain=NSCocoaErrorDomain Code=259 "Cannot retrive binary file from bundle at file:///project-path/Carthage/Build/iOS/HexColors.franework/" UserInfo={NSLocalizedDescription=Cannot retrive binary file from bundle at file:///project-path/Carthage/Build/iOS/HexColors.franework/, NSLocalizedRecoverySuggestion=Does the bundle contain an Info.plist?}
Command PhaseScriptExecution failed with a nonzero exit code
In your documentation you say import HexColors.h
I think you mean import HexColor.h
I think the method should accept both @"#ffffff" and @"ffffff". I'd be more than happy to add this functionality and create a pull request.
for example
(HXColor *)colorWithAlphaHexString:(NSString *)hexString
{
// Check for hash and add the missing hash. E.g. # 80 FF FF FF
if('#' != [hexString characterAtIndex:0])
{
hexString = [NSString stringWithFormat:@"#%@", hexString];
}
// check for string length
assert(9 == hexString.length );
NSString *alpha = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(1, 2)]];
float alphaFloat = [[self class] hexValueToFloat:alpha];
NSString *redHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(3, 2)]];
unsigned redInt = [[self class] hexValueToUnsigned:redHex];
NSString *greenHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(5, 2)]];
unsigned greenInt = [[self class] hexValueToUnsigned:greenHex];
NSString *blueHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(7, 2)]];
unsigned blueInt = [[self class] hexValueToUnsigned:blueHex];
HXColor *color = [HXColor colorWith8BitRed:redInt green:greenInt blue:blueInt alpha:alphaFloat];
return color;
}
(CGFloat)hexValueToFloat:(NSString *)hexValue
{
float value = 0.0;
NSScanner *hexValueScanner = [NSScanner scannerWithString:hexValue];
[hexValueScanner scanFloat:&value];
return value;
}
Line 33 in HexColor.m
assert(7 == hexString.length || 4 == hexString.length);
This crashes the app if the hexString is not the right length. I'd be nice if it just provided a default color instead of crashing. My solution:
if (7 != hexString.length && 4 != hexString.length) {
NSString *defaultHex = [NSString stringWithFormat:@"0xff"];
unsigned defaultInt = [[self class] hexValueToUnsigned:defaultHex];
HXColor *color = [HXColor colorWith8BitRed:defaultInt green:defaultInt blue:defaultInt alpha:1.0];
return color;
}
It's not perfect, but I think providing a wrong color is a much better experience than crashing the app. Also, I think error handling belongs inside that library rather than outside of it.
Thanks
I'm using this Pod in a new Mac app (targeting 10.11) and I discovered a weird issue while writing tests for my color extension.
NSColor.hx_colorWithHexString("#99999955")
This should return an RGB of 153,153,153. When it gets to hx_colorWith8BitRed it is trying to create an NSColor colorWithCalibratedRed using 153,153,85. This seems to work whenever I leave off the alpha characters, but is returning the wrong value for blue.
I am getting this error on compile while using HexColors and TSMessages along with about 20 more errors, all related to HXColor.
I think they are swizzleing +colorWithHexString:
internally or something. I don't think there is anything we can do in this repo to solve this except go yell at https://twitter.com/tapjoy.
The work around I found was to use +colorWithHexString:alpha:
.
Hey can you release a new version of HexColors for the last 2 commits? Unfortunately I can't add HexColors as a dependency to my pod without xcodebuild complaining π :
WARN | xcodebuild: HexColors/Sources/HexColors.swift:74:21: warning: 'characters' is deprecated: Please use String or Substring directly
Making matters worse the PodSpec spec wonβt allow me to pin HexColors to the latest commit. So, yea.. This wont stop me from putting out a new version of my pod which depends on Hexcolors but it'd be nice to get rid of these warnings.
Please Support Objective-C. i use cocoapods to install this podspec, but it say must use "user_framework", when i add it ,some podspec contains static library will not be installed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.