This repository was archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 415
Added support for UIColor #25
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
09e9082
Add UIColor property binding to a tweak.
sgl0v c6d9f3b
Implemented FBSliderView control. Represents a regular slider with ab…
sgl0v 059b5a9
Created ColorWheel class for color selection(hue and saturation compo…
sgl0v f9488fc
Updated color wheel bitmap generation, fixed code style formatting, a…
sgl0v 8856bcb
Implemented view controller to select a color with RGBA components.
sgl0v f179ee7
Modified: target-action notifying, when the slider's value changed; U…
sgl0v ad5e84a
Implemented view, that contains UI elements to select color value fro…
sgl0v f88b6bc
Integrated color selection with the example the project.
sgl0v 7be7941
Springs&struts substituted with autolayout constraints for color sele…
sgl0v 41c3bcd
Fixed auto layout constraints for color components views.
sgl0v f2eda9e
Changed mechanism of adjusting scrollview when the keyboard appears/d…
sgl0v 45c9997
Code refactored, added comments.
sgl0v c96b4d1
Code refactored, updated unit tests, created category for UIColor.
sgl0v 2718a83
Code refactored.
sgl0v b7ff467
Moved UI construction & setting layout constraints to the separate vi…
sgl0v 29a43d5
Added view controller & views to select color using HSB color space.
sgl0v 3a4fa8e
Implemented view, that contains UI elements to select color value fro…
sgl0v 0266e29
Implemented keyboard manager
sgl0v 23fc6ec
Changed keyboard manager to make it reusable all over the project.
sgl0v 85c4c8c
Refactored rgba color components selection view.
sgl0v 15e2bf4
Implemented color selection controller. Refactored RGB & HSB color vi…
sgl0v 66a0e80
Code refactored, implemented color selection controller , resolved pr…
sgl0v fc6d3c4
Added Facebook licence to the _FBSliderView.m file.
sgl0v df24db0
Changed thumb position calculation in the _FBSliderView class.
sgl0v 6e6fca5
Changed the autolayout constraints that cause the application crash f…
sgl0v 4b87bf8
Merge branch 'master' into color
sgl0v 8b62da2
Removed the global keyboard manager the FBTweakShakeWindow. Defined t…
sgl0v 098ff94
Added the '_' prefix for private classes.
sgl0v a1af7bd
Moved to the UITableView usage in order to make application UI more c…
sgl0v b532683
Added the pan gesture recognizer to handle tap gestures on the color …
sgl0v 2fed6de
Replaced the hex-string based solution with UIColor one. Added the la…
sgl0v e9105f4
Defined function that creates the color wheel.
sgl0v 94da040
Removed the _FBColorWheelView. Defined all needed UI in the _FBColorW…
sgl0v eab620c
Had to specify the property explicitly to bind UIColor. Now we use d…
sgl0v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
Copyright (c) 2014-present, Facebook, Inc. | ||
All rights reserved. | ||
|
||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class _FBColorComponentCell; | ||
|
||
@protocol _FBColorComponentCellDelegate <NSObject> | ||
|
||
- (void)colorComponentCell:(_FBColorComponentCell*)cell didChangeValue:(CGFloat)value; | ||
|
||
@end | ||
|
||
/** | ||
@abstract A cell to edit a color component. | ||
*/ | ||
@interface _FBColorComponentCell : UITableViewCell | ||
|
||
//! @abstract The title. | ||
@property(nonatomic, copy) NSString *title; | ||
|
||
//! @abstract The current value. The default value is 0.0. | ||
@property(nonatomic, assign) CGFloat value; | ||
|
||
//! @abstract The minimum value. The default value is 0.0. | ||
@property(nonatomic, assign) CGFloat minimumValue; | ||
|
||
//! @abstract The maximum value. The default value is 255.0. | ||
@property(nonatomic, assign) CGFloat maximumValue; | ||
|
||
//! @abstract The format string to apply for textfield value. `%.f` by default. | ||
@property(nonatomic, copy) NSString *format; | ||
|
||
//! @abstract The array of CGColorRef objects defining the color of each gradient stop on the track. | ||
@property(nonatomic, copy) NSArray *colors; | ||
|
||
//! @abstract The cell's delegate. | ||
@property(nonatomic, weak) id<_FBColorComponentCellDelegate> delegate; | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/** | ||
Copyright (c) 2014-present, Facebook, Inc. | ||
All rights reserved. | ||
|
||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import "_FBColorComponentCell.h" | ||
#import "_FBSliderView.h" | ||
|
||
extern CGFloat const _FBRGBColorComponentMaxValue; | ||
static CGFloat const _FBColorComponentMargin = 5.0f; | ||
static CGFloat const _FBColorComponentTextSpacing = 10.0f; | ||
static CGFloat const _FBColorComponentTextFieldWidth = 50.0f; | ||
|
||
@interface _FBColorComponentCell () <UITextFieldDelegate> | ||
|
||
@end | ||
|
||
@implementation _FBColorComponentCell { | ||
UILabel *_label; | ||
_FBSliderView *_slider; | ||
UITextField *_textField; | ||
} | ||
|
||
- (instancetype)init | ||
{ | ||
if ((self = [super init])) { | ||
[self _init]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)setTitle:(NSString *)title | ||
{ | ||
_label.text = title; | ||
} | ||
|
||
- (void)setMinimumValue:(CGFloat)minimumValue | ||
{ | ||
_slider.minimumValue = minimumValue; | ||
} | ||
|
||
- (void)setMaximumValue:(CGFloat)maximumValue | ||
{ | ||
_slider.maximumValue = maximumValue; | ||
} | ||
|
||
- (void)setValue:(CGFloat)value | ||
{ | ||
_slider.value = value; | ||
_textField.text = [NSString stringWithFormat:_format, value]; | ||
} | ||
|
||
- (NSString*)title | ||
{ | ||
return _label.text; | ||
} | ||
|
||
- (CGFloat)minimumValue | ||
{ | ||
return _slider.minimumValue; | ||
} | ||
|
||
- (CGFloat)maximumValue | ||
{ | ||
return _slider.maximumValue; | ||
} | ||
|
||
- (CGFloat)value | ||
{ | ||
return _slider.value; | ||
} | ||
|
||
- (void)setColors:(NSArray *)colors | ||
{ | ||
_slider.colors = colors; | ||
} | ||
|
||
- (NSArray *)colors | ||
{ | ||
return _slider.colors; | ||
} | ||
|
||
#pragma mark - UITextFieldDelegate methods | ||
|
||
- (void)textFieldDidEndEditing:(UITextField *)textField | ||
{ | ||
[self setValue:[textField.text floatValue]]; | ||
[self.delegate colorComponentCell:self didChangeValue:self.value]; | ||
} | ||
|
||
- (BOOL)textFieldShouldReturn:(UITextField *)textField | ||
{ | ||
[textField resignFirstResponder]; | ||
return YES; | ||
} | ||
|
||
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | ||
{ | ||
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; | ||
|
||
//first, check if the new string is numeric only. If not, return NO; | ||
if ([newString rangeOfCharacterFromSet:[self _invertedDecimalDigitAndDotCharacterSet]].location != NSNotFound) { | ||
return NO; | ||
} | ||
|
||
return [newString floatValue] <= _slider.maximumValue; | ||
} | ||
|
||
-(void)layoutSubviews | ||
{ | ||
[super layoutSubviews]; | ||
|
||
CGFloat cellHeight = CGRectGetHeight(self.bounds); | ||
CGFloat cellWidth = CGRectGetWidth(self.bounds); | ||
CGFloat labelWidth = [_label sizeThatFits:CGSizeZero].width; | ||
_label.frame = CGRectIntegral((CGRect){_FBColorComponentMargin, _FBColorComponentMargin, labelWidth, cellHeight - 2 * _FBColorComponentMargin}); | ||
_textField.frame = CGRectIntegral((CGRect){cellWidth - _FBColorComponentMargin - _FBColorComponentTextFieldWidth, _FBColorComponentMargin, _FBColorComponentTextFieldWidth, cellHeight - 2 * _FBColorComponentMargin}); | ||
CGFloat sliderWidth = CGRectGetMinX(_textField.frame) - CGRectGetMaxX(_label.frame) - 2 * _FBColorComponentTextSpacing; | ||
_slider.frame = CGRectIntegral((CGRect){CGRectGetMaxX(_label.frame) + _FBColorComponentTextSpacing, _FBColorComponentMargin, sliderWidth, cellHeight - 2 * _FBColorComponentMargin}); | ||
} | ||
|
||
#pragma mark - Private methods | ||
|
||
- (void)_init | ||
{ | ||
self.selectionStyle = UITableViewCellSelectionStyleNone; | ||
|
||
_format = @"%.f"; | ||
|
||
_label = [[UILabel alloc] init]; | ||
_label.adjustsFontSizeToFitWidth = YES; | ||
[self.contentView addSubview:_label]; | ||
|
||
_slider = [[_FBSliderView alloc] init]; | ||
_slider.maximumValue = _FBRGBColorComponentMaxValue; | ||
[self.contentView addSubview:_slider]; | ||
|
||
_textField = [[UITextField alloc] init]; | ||
_textField.textAlignment = NSTextAlignmentCenter; | ||
[_textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; | ||
[self.contentView addSubview:_textField]; | ||
|
||
[self setValue:0.0f]; | ||
[_slider addTarget:self action:@selector(_didChangeSliderValue:) forControlEvents:UIControlEventValueChanged]; | ||
[_textField setDelegate:self]; | ||
} | ||
|
||
- (void)_didChangeSliderValue:(_FBSliderView*)sender | ||
{ | ||
[self setValue:sender.value]; | ||
[self.delegate colorComponentCell:self didChangeValue:self.value]; | ||
} | ||
|
||
- (NSCharacterSet*)_invertedDecimalDigitAndDotCharacterSet | ||
{ | ||
NSMutableCharacterSet *characterSet = [NSMutableCharacterSet decimalDigitCharacterSet]; | ||
[characterSet addCharactersInString:@"."]; | ||
return [[characterSet invertedSet] copy]; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
Copyright (c) 2014-present, Facebook, Inc. | ||
All rights reserved. | ||
|
||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
typedef struct { CGFloat red, green, blue, alpha; } RGB; | ||
typedef struct { CGFloat hue, saturation, brightness, alpha; } HSB; | ||
|
||
extern CGFloat const _FBRGBColorComponentMaxValue; | ||
extern CGFloat const _FBAlphaComponentMaxValue; | ||
extern CGFloat const _FBHSBColorComponentMaxValue; | ||
extern NSUInteger const _FBRGBAColorComponentsSize; | ||
extern NSUInteger const _FBHSBAColorComponentsSize; | ||
|
||
typedef NS_ENUM(NSUInteger, _FBRGBColorComponent) { | ||
_FBRGBColorComponentRed, | ||
_FBRGBColorComponentGreed, | ||
_FBRGBColorComponentBlue, | ||
_FBRGBColorComponentAlpha | ||
}; | ||
|
||
typedef NS_ENUM(NSUInteger, _FBHSBColorComponent) { | ||
_FBHSBColorComponentHue, | ||
_FBHSBColorComponentSaturation, | ||
_FBHSBColorComponentBrightness, | ||
_FBHSBColorComponentAlpha | ||
}; | ||
|
||
/** | ||
* Converts an RGB color value to HSV. | ||
* Assumes r, g, and b are contained in the set [0, 1] and | ||
* returns h, s, and b in the set [0, 1]. | ||
* | ||
* @param rgb The rgb color values | ||
* @return The hsb color values | ||
*/ | ||
extern HSB _FBRGB2HSB(RGB rgb); | ||
|
||
/** | ||
* Converts an HSB color value to RGB. | ||
* Assumes h, s, and b are contained in the set [0, 1] and | ||
* returns r, g, and b in the set [0, 255]. | ||
* | ||
* @param hsb The hsb color values | ||
* @return The rgb color values | ||
*/ | ||
extern RGB _FBHSB2RGB(HSB hsb); | ||
|
||
/** | ||
* Returns the rgb values of the color components. | ||
* | ||
* @param color The color value. | ||
* | ||
* @return The values of the color components (including alpha). | ||
*/ | ||
extern RGB _FBRGBColorComponents(UIColor *color); | ||
|
||
/** | ||
* Returns the color wheel's hue value according to the position, color wheel's center and radius. | ||
* | ||
* @param position The position in the color wheel. | ||
* @param center The color wheel's center. | ||
* @param radius The color wheel's radius. | ||
* | ||
* @return The hue value. | ||
*/ | ||
extern CGFloat _FBGetColorWheelHue(CGPoint position, CGPoint center, CGFloat radius); | ||
|
||
/** | ||
* Returns the color wheel's saturation value according to the position, color wheel's center and radius. | ||
* | ||
* @param position The position in the color wheel. | ||
* @param center The color wheel's center. | ||
* @param radius The color wheel's radius. | ||
* | ||
* @return The saturation value. | ||
*/ | ||
extern CGFloat _FBGetColorWheelSaturation(CGPoint position, CGPoint center, CGFloat radius); | ||
|
||
/** | ||
* Creates the color wheel with specified diameter. | ||
* | ||
* @param diameter The color wheel's diameter. | ||
* | ||
* @return The color wheel image. | ||
*/ | ||
extern CGImageRef _FBCreateColorWheelImage(CGFloat diameter); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dot synatx