Skip to content
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
6 changes: 6 additions & 0 deletions MSColorPicker/MSColorSelectionViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// THE SOFTWARE.

#import <UIKit/UIKit.h>
#import "MSColorSelectionView.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -59,6 +60,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, strong) UIColor *color;

/**
* The current colorView mode: RGB or HSB
*/
@property (nonatomic, assign) MSSelectedColorView colorViewMode;

@end

NS_ASSUME_NONNULL_END
31 changes: 25 additions & 6 deletions MSColorPicker/MSColorSelectionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

@interface MSColorSelectionViewController () <MSColorViewDelegate>

@property (nonatomic, strong) UISegmentedControl *modeSelectionControl;

@end

@implementation MSColorSelectionViewController
Expand All @@ -46,26 +48,43 @@ - (void)viewDidLoad
{
[super viewDidLoad];

UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:@[NSLocalizedString(@"RGB", ), NSLocalizedString(@"HSB", )]];
[segmentControl addTarget:self action:@selector(segmentControlDidChangeValue:) forControlEvents:UIControlEventValueChanged];
segmentControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentControl;
self.navigationItem.titleView = self.modeSelectionControl;

[self.colorSelectionView setSelectedIndex:0 animated:NO];
[self.colorSelectionView setSelectedIndex:self.colorViewMode animated:NO];
self.colorSelectionView.delegate = self;
self.edgesForExtendedLayout = UIRectEdgeNone;
}

- (IBAction)segmentControlDidChangeValue:(UISegmentedControl *)segmentedControl
{
[self.colorSelectionView setSelectedIndex:segmentedControl.selectedSegmentIndex animated:YES];
if (segmentedControl == self.modeSelectionControl) {
self.colorViewMode = segmentedControl.selectedSegmentIndex;
}
}

- (void)setColor:(UIColor *)color
{
self.colorSelectionView.color = color;
}

- (void)setColorViewMode:(MSSelectedColorView)selectedColorViewMode
{
if (selectedColorViewMode != _colorViewMode) {
_colorViewMode = selectedColorViewMode;
[self.colorSelectionView setSelectedIndex:_colorViewMode animated:YES];
self.modeSelectionControl.selectedSegmentIndex = _colorViewMode;
}
}

-(UISegmentedControl *)modeSelectionControl {
if (_modeSelectionControl == nil) {
_modeSelectionControl = [[UISegmentedControl alloc] initWithItems:@[NSLocalizedString(@"RGB", ), NSLocalizedString(@"HSB", )]];
[_modeSelectionControl addTarget:self action:@selector(segmentControlDidChangeValue:) forControlEvents:UIControlEventValueChanged];
_modeSelectionControl.selectedSegmentIndex = self.colorViewMode;
}
return _modeSelectionControl;
}

- (UIColor *)color
{
return self.colorSelectionView.color;
Expand Down