vicc / chameleon Goto Github PK
View Code? Open in Web Editor NEWColor framework for Swift & Objective-C (Gradient colors, hexcode support, colors from images & more).
License: Other
Color framework for Swift & Objective-C (Gradient colors, hexcode support, colors from images & more).
License: Other
color.flatten
calls colorWithFlatVersionFrom(self)
, then [color getLightness:nil valueForA:nil valueForB:nil alpha:&colorAlpha];
. Inside getLightness
there's this code:
*L = [LABValues[0] floatValue];
*A = [LABValues[1] floatValue];
*B = [LABValues[2] floatValue];
but they are all nil
The following line in AppDelegate makes navigationBar background and text color white.
Chameleon.setGlobalThemeUsingPrimaryColor(FlatMint(), withSecondaryColor: FlatBlue(), andContentStyle: UIContentStyle.Contrast)
I'm using iPhone 4S with iOS 7.1.1 installed.
My app works fine on 4S simulator, but when I run it in the real device, it crashes with the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:'
When I remove setGlobalTheme, the app runs without problems.
It also works fine on a iPhone 5S with iOS 8.4.1 installed (real device).
Any hints on what may be causing the problem? I found related issues with the same error that pointed to disabling navBar translucence, but that didn't help me.
Ignoring it for now ?
Hello! Awesome library btw. I ran into an issue which I think can easily be solved but my brain isn't working too right at the moment. I have a UITableView that has over a 100+ cells. Easy enough to apply a gradient to the TableView background. The problem starts when I scroll down the gradient doesn't scroll with the content. Basically it clips at a certain point and starts over again when the tableview cells are reused.
Here's my code. I use the tableView's frame...
- (void)updateGradient {
UIColor *gradientBG = [UIColor colorWithGradientStyle:UIGradientStyleTopToBottom
withFrame:self.tableView.frame
andColors:@[[UIColor flatBlueColor], [UIColor lightGrayColor]]];
[self.tableView setOpaque:NO];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.view setBackgroundColor:gradientBG];
}
Currently in the UIColor class extension there are some class methods that return arrays of numbers representing RGB values for the flat colors. Currently these methods return arrays of strings:
return @[@"38", @"52", @"94", ...];
Which are then casted to NSNumber instances to get the float value:
[((NSNumber *)[[self redValues] objectAtIndex:i-1]) floatValue]
This is totally unnecessary! You can use the NSNumber literal syntax instead when creating the array:
return @[@38, @52, @94, ...];
And you can also use [[self redValues][i - 1] floatValue]
to simplify the other set of code, although you probably ought not to constantly recreate the array in each iteration of the loop by calling the function to create the array over and over again.
Shouldn't UIColor.yellowColor().flatten()
return something "similar" at least to FlatYellow or FlatYellowDark instead of a black shade ?
Update: Works as intended. But for some reason UIViewControllers have black background as default
#pragma mark - Class Methods
sectionUIViewController+Chameleon.h
the method flatify()
is empty (Line 97)findColorsOfImage(...)
, won't the NSArray and NSCountedSet have the same colors ?In my opinion it is better to use HSB colors as they are closer to human eye perception than RGB. When you have a distance between 2 colors it is more likely that their appearance is closer in HSB color space than in RGB.
Attempting to style a gradient background using the code below renders a solid black background.
let colors:[UIColor] = [
UIColor(red: 0/255, green: 118/255, blue: 162/255, alpha: 1.0),
UIColor(red: 0/255, green: 85/255, blue: 116/255, alpha: 1.0)
]
self.backgroundColor = GradientColor(.TopToBottom, self.frame, colors)
Xcode 7
iOS9
Swift 2
SpriteKit
Hi,
SFSafariViewController views presented in apps using Chameleon are using part of the color scheme, and they do not look ok.
For instance, to the demo app I added an IBAction to the example button with the code:
@IBAction func openSafari(sender: AnyObject) {
if #available(iOS 9.0, *) {
let safariView = SFSafariViewController(URL: NSURL(string: "https://duckduckgo.com")!)
self.presentViewController(safariView, animated: true, completion: nil)
}
}
When clicking the button the presented SFSafariViewController looks:
You can notice the URL bar and the done button have the background color, but the rest of the navbar and status bars have the standard grey.
Is there a way to have the SFSafariViewController fully themed or can I add an exception to leave SFSafariViewController with the default color schema?
Thanks!
Hi @bre7!
Just updated Chameleon to 2.0. There might be some conflicts with Swift Macros though since several have been deprecated. It would be awesome if you can check it out real quick. Also if you have time, could you add some Swift examples for the new features in the documentation! Thanks!!! ๐
Hi,
is there any configuration in pod's file can define version for objc?
From Cocoapods:
[!] Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add `use_frameworks!` to your Podfile or target to opt into using it.
I am getting an EXC_BAD_ACCESS error on the following line in UIColor+ChameleonPrivate:
*L = [LABValues[0] floatValue];
(L = NULL)
Why is this? I installed manually, not with CocoaPods (I just dragged the files into my project and imported Chameleon.h - no other errors)
Hello,
the above function does not work on a given image, neither with both true and false for the parameter isFlatScheme. The AverageColor function works fine on the same image.
What could lead to this problem?
Love the framework, but we're running into an issue where it looks like Chameleon's colour-generation is leaking.
We're using the +arrayOfColorsFromImage:withFlatScheme:(BOOL)isFlatScheme
to generate complementary colours around our main image. Calling this even around 7 times resulting in our persistent memory usage doubling.
When I dig into how the method works internally, I'm noticing that removing the call to CGContextDrawImage
from UIColor+ChameleonPrivate.m:50
, the high memory usage ceases.
Is anyone able to replicate this?
1.1.3 missing :D
USUALLY THE INPUT OF A CERTAIN VARIABLE LIKE "GRADIENTSTYLE" STARTS WITH THE WORD "GRADIENTSTYLE" INSTEAD OF JUST "LINEARLEFTTORIGHT"
colorWithContrastingBlackOrWhiteColorOn in 1.1.0 no longer producing contrasting colors, returns color exactly matching the color passed as parameter.
Is it planned?
And Xcode 6
I've been using Chameleon in my app for about 18 months and I haven't had a problem. I changed my app to use cocoapods (along with other updates) so I had to update all the #import
statements from #import "Chameleon.h"
to #import <ChameleonFramework/Chameleon.h>
.
I'm now receiving an error when I use either ComplementaryFlatColor
or ContrastColor
. The error I receive is
+[UIColor colorWithComplementaryFlatColorOf:]: unrecognized selector sent to class 0x104909708 +[CATransaction synchronize] called within transaction +[CATransaction synchronize] called within transaction +[CATransaction synchronize] called within transaction *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIColor colorWithComplementaryFlatColorOf:]: unrecognized selector sent to class 0x104909708'
I have verified the Chameleon files imported properly because I can โ-click either macro and it takes me to the ChameleonMacros.h
file and their #define statement. I've confirmed that Chameleon.h
imports the macro file. I've set a breakpoint on the line + (UIColor *)colorWithComplementaryFlatColorOf:(UIColor *)color
as well as + (UIColor *)colorWithComplementaryFlatColorOf:(UIColor *)color withAlpha:(CGFloat)alpha
but the breakpoints are not hit.
Here is my code and I'll explain the relevant parts below:
The colorHome
variable is a UIColor. The self.homeTeamName.backgroundColor
is the background color of a UILabel. I thought I might be sending an empty color to the function so I checked colorHome
and verified it contained a color:
All of this exact same code worked prior to moving to cocoapods and for various reasons I don't/can't move back to the way the app used to be written. Can you please provide some guidance on what I need to look for to resolve this issue? Also, I'm not sure why I started to receive the +[CATransaction synchronize] called within transaction
errors, either. I haven't seen those errors until now so I think it's related. Thanks.
let kColorTheme = NSArray(ofColorsWithColorScheme: ColorSchemeComplementary, for: UIColor.redColor(), flatScheme: true)
will never pass Xcode for Swift. It keeps blocking errors:
Is for:
a forbidden parameter keyword in Swift?
It seems to me that the compiler is looking for the method:
+ (NSArray *)arrayOfColorsWithColorScheme:(ColorScheme)colorScheme for:(UIColor *)color flatScheme:(BOOL)isFlatScheme;
but the method, found in NSArray+Chameleon.h/m is the following:
+ (NSArray *)arrayOfColorsWithColorScheme:(ColorScheme)colorScheme with:(UIColor *)color flatScheme:(BOOL)isFlatScheme;
(with should be for)
[[UINavigationBar appearance] setBarTintColor:GradientColor(UIGradientStyleLeftToRight,
CGRectMake(0, 0, 1024, 64),
(@[FlatGreenDark, FlatGreen]))];
The result is a dark gray navigation bar.
I'm facing an issue for the first time with the framework. I'm getting an invalid context error when trying to set a view's background color with a gradient color. Bellow is my code :
UIView * view = [[UIView alloc]initWithFrame:frame];
UIColor *lightYellow = [UIColor colorwithHexString:@"#98c168" alpha:0.9];
UIColor *darkYellow = [UIColor colorwithHexString:@"#f5eb08" alpha:0.9];
NSArray * yellowArray = [NSArray arrayWithObjects:lightYellow, darkYellow, nil];
view.backgroundColor = GradientColor(UIGradientStyleTopToBottom, frame, yellowArray);
The complete description of the error :
: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Same error for : CGContextSaveGState , CGContextClipToRect, CGContextTranslateCTM, CGContextScaleCTM, CGContextDrawLinearGradient, CGContextRestoreGState, CGContextRestoreGState
.
I use 'EDColor' and 'ChameleonFramework' in pod, Could add a prefix to category 'CIELAB' on interface 'UIColor' ?
iphonesimulator/ChameleonFramework.framework/Headers/UIColor+CIELAB.h:33:12: warning: duplicate definition of category 'CIELAB' on interface 'UIColor'
@interface UIColor (CIELAB)
I'm having problems adding the files to my swift project. I keep getting errors in the short hand class. Can you please explaining a little bit more on how to integrate it?
Thank you
I read through documentation twice and there's no mention of setting global UIAppearance.
I'd like to set colors once in AppDelegate globally and not insert 'set color' into each and every one view controller.
What is the best practice for setting global UIAppearance or is there an example?
when set [Chameleon setGlobalThemeUsingPrimaryColor:[UIColor flatBlueColor] withContentStyle:UIContentStyleContrast];
UIStatusBar
and UITableViewCell
display the wrong color.
I want to take the time to thank the following individuals...
@aekwan @alist @bre7 @cascio @ddwang @jmhooper @peacemoon @saullopez @sfader @smokyonion & @jherran
I've been busy working on a separate project for the last couple of months, which prevented me from being as involved with Chameleon as I would have liked. I feel like I never had the change to truly thank all of you for taking the time to check out Chameleon and contribute to it. Your contributions / pull requests / comments / and advice have definitely helped out. Cheers to all of you for truly being amazing! ๐ป๐
I figured the least I could do was add all of you to the Special Thanks section, while also giving you credit for fixes in the Change Log section.
Again thank you for helping out, and good luck on all your projects!
๐๐๐๐๐๐ป๐๐๐๐
Best,
Vicc
@bre7 I didn't want to move the Chameleon.h
file you added just in case it broke any dependencies, however I added a copy back into the Pod folder to fix the error.
Doesn't seem like necessary (Most values appear to be non-null and they are implicitly unwrapped optionals in Swift unless stated otherwise by annotations)
Is it possible to use the chameleon shorthand in Swift? It doesn't seem to be autocompleting in Xcode.
I installed the latest version using CocoaPods and added Chameleon/Chameleon.h to my bridging header.
I get the error "No such module" on import ChameleonFramework in the Swift file. I have done the manual installation. Any solution? (Also tried cleaning and rebuilding)
The current version of Chameleon forces hidden hairline in all navigationBars throughout an app. While for some instances this is correct, I use Chameleon mainly for flat colors and missing hairline in navigation bars really messes up my UI. Is it necessary to force the hairline to be hidden?
Here's the code UINavigationController+Chameleon.m
:
- (void)chameleon_viewDidLoad {
[self chameleon_viewDidLoad];
UIView *heairlineImageView = [self findHairlineImageViewUnder:self.navigationBar];
if (heairlineImageView) {
heairlineImageView.hidden = NO; // I changed it from YES
}
}
Other than that this is an awesome framework! Thanks! :D
So not all color libraries are created equal :) Notably https://github.com/thisandagain/color has a lot of overlap with Chameleon, with many other color palettes - you might want to check it out.
? You can never have too many colors ๐ฌ๐ฌ๐ฌ
First of all I want to thank you for this wonderful library that makes IOS development easier.
I would like to ask if Chameleon currently supports altering the angle of a linearGradient UIColor?
Thank you very much!
I wonder when will have an update for the swift 2.0 and IOS 9.
Thanks.
I read the documentation and did the installation for cocoapods and import for my project the ChameleonShorthand.swift, when build the project give me the following error:
/ChameleonShorthand.swift:41:38: Use of undeclared type 'UIShadeStyle'
/ChameleonShorthand.swift:49:35: Use of undeclared type 'UIGradientStyle'
/ChameleonShorthand.swift:65:36: Use of undeclared type 'ColorScheme'
/ChameleonShorthand.swift:58:12: Use of unresolved identifier 'ChameleonStatusBar'
Another alert that the xcode this giving is:
/ChameleonFramework/Pod/Classes/Objective-C/UIColor+Chameleon.m:374:9: Value stored to 'backgroundColor' is never read
Can you help me?
Thanks a lot
I was having a 1-pixel wrap around from bottom to top for certain UIColors generated by
+ (UIColor *)colorWithGradientStyle:(UIGradientStyle)gradientStyle
I resolved it locally by having the UIGraphics context use the current screen's scale
UIGraphicsBeginImageContextWithOptions(backgroundGradientLayer.bounds.size,NO, [UIScreen mainScreen].scale);
Take a look at this diff:
master...alist:master#diff-d75ec200ce59d4e5a90a77e80cc5af5d
Hi, i'm trying to add a gradient background for my UIView but, unfortunately, it don't fit with my desired width (screen width). The gradient contains black + transparent.
Code:
let colors:[UIColor] = [.blackColor(), .clearColor()]
fadeBackground.backgroundColor = GradientColor(.LeftToRight, fadeBackground.frame, colors)
*ps is my first project in iOS and i'm working with Swift
Portrait:
Landscape:
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.