123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- //
- // PDFSettingsColorViewController.m
- // PDFReader
- //
- // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
- //
- // The PDF Reader Sample applications are licensed with a modified BSD license.
- // Please see License for details. This notice may not be removed from this file.
- //
- #import "PDFSettingsColorViewController.h"
- @interface PDFViewColorSlider : UISlider
- @property (nonatomic,retain) CAGradientLayer *gradientLayer;
- - (void)setColors:(NSArray *)colors;
- @end
- @implementation PDFViewColorSlider
- - (instancetype)initWithCoder:(NSCoder *)aDecoder {
- if (self = [super initWithCoder:aDecoder]) {
- CAGradientLayer *gradientLayer = [CAGradientLayer layer];
- gradientLayer.cornerRadius = 2.0f;
- gradientLayer.startPoint = CGPointMake(0.0f, 0.5f);
- gradientLayer.endPoint = CGPointMake(1.0f, 0.5f);
- [self.layer addSublayer:gradientLayer];
- self.gradientLayer = gradientLayer;
-
- self.continuous = NO;
- self.minimumValue = 0;
- self.maximumValue = 1;
- self.minimumTrackTintColor = [UIColor clearColor];
- self.maximumTrackTintColor = [UIColor clearColor];
- }
- return self;
- }
- - (void)setColors:(NSArray *)colors {
- self.gradientLayer.colors = colors;
- }
- - (void)dealloc {
- [_gradientLayer release];
- [super dealloc];
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- CGRect rect = [self trackRectForBounds:self.bounds];
- rect.origin.y -= 5;
- rect.size.height += 10;
- self.gradientLayer.frame = rect;
- }
- @end
- @interface PDFSettingsColorViewController () <UIPopoverPresentationControllerDelegate>
- @property (nonatomic,assign) IBOutlet UIView *colorView;
- @property (nonatomic,assign) IBOutlet PDFViewColorSlider *hueSlider;
- @property (nonatomic,assign) IBOutlet PDFViewColorSlider *saturationSlider;
- @property (nonatomic,assign) IBOutlet PDFViewColorSlider *brightnessSlider;
- @property (nonatomic,assign) CGFloat hue;
- @property (nonatomic,assign) CGFloat saturation;
- @property (nonatomic,assign) CGFloat brightness;
- @end
- @implementation PDFSettingsColorViewController
- #pragma mark - Init Methods
- - (instancetype)initWithCoder:(NSCoder *)aDecoder {
- if (self = [super initWithCoder:aDecoder]) {
- _hue = 0;
- _saturation = 1;
- _brightness = 1;
- }
- return self;
- }
- - (void)dealloc {
- Block_release(_callback);
- [super dealloc];
- }
- #pragma mark - UIViewController Methods
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // Do any additional setup after loading the view.
- self.preferredContentSize = CGSizeMake(280, 320);
-
- self.colorView.layer.cornerRadius = self.colorView.bounds.size.width/2.0;
- self.colorView.superview.layer.cornerRadius = self.colorView.superview.bounds.size.width/2.0;
- self.colorView.superview.layer.borderWidth = 1;
- self.colorView.superview.layer.borderColor = [UIColor colorWithRed:197.0/255.0 green:197.0/255.0 blue:197.0/255.0 alpha:1.0].CGColor;
-
- [self reloadData];
- }
- - (IBAction)sliderValueChanged_Color:(id)sender {
- self.hue = self.hueSlider.value;
- self.saturation = self.saturationSlider.value;
- self.brightness = self.brightnessSlider.value;
- [self reloadData];
-
- if (self.callback) {
- self.callback();
- }
- }
- - (void)reloadData {
- self.hueSlider.value = self.hue;
- self.saturationSlider.value = self.saturation;
- self.brightnessSlider.value = self.brightness;
-
- [self.hueSlider setColors:@[(id)[[UIColor colorWithHue:0
- saturation:self.saturation
- brightness:self.brightness
- alpha:1] CGColor],
- (id)[[UIColor colorWithHue:0.25
- saturation:self.saturation
- brightness:self.brightness
- alpha:1] CGColor],
- (id)[[UIColor colorWithHue:0.5
- saturation:self.saturation
- brightness:self.brightness
- alpha:1] CGColor],
- (id)[[UIColor colorWithHue:0.75
- saturation:self.saturation
- brightness:self.brightness
- alpha:1] CGColor],
- (id)[[UIColor colorWithHue:1
- saturation:self.saturation
- brightness:self.brightness
- alpha:1] CGColor]]];
- [self.saturationSlider setColors:@[(id)[[UIColor colorWithHue:self.hue
- saturation:0
- brightness:self.brightness
- alpha:1] CGColor],
- (id)[[UIColor colorWithHue:self.hue
- saturation:1
- brightness:self.brightness
- alpha:1] CGColor]]];
- [self.brightnessSlider setColors:@[(id)[[UIColor colorWithHue:self.hue
- saturation:self.saturation
- brightness:0
- alpha:1] CGColor],
- (id)[[UIColor colorWithHue:self.hue
- saturation:self.saturation
- brightness:1
- alpha:1] CGColor]]];
-
- self.colorView.backgroundColor = [UIColor colorWithHue:self.hue saturation:self.saturation brightness:self.brightness alpha:1];
- }
- #pragma mark - Public Methods
- - (void)setColor:(UIColor *)color {
- if (color) {
- [color getHue:&_hue saturation:&_saturation brightness:&_brightness alpha:NULL];
- }
- }
- - (UIColor *)color {
- return [UIColor colorWithHue:self.hue saturation:self.saturation brightness:self.brightness alpha:1.0];
- }
- - (void)showViewController:(UIViewController *)viewController inRect:(CGRect)rect {
- self.modalPresentationStyle = UIModalPresentationPopover;
- UIPopoverPresentationController *popVC = self.popoverPresentationController;
- popVC.delegate = self;
- popVC.sourceRect = rect;
- popVC.sourceView = viewController.view;
- [viewController presentViewController:self animated:YES completion:nil];
- }
- #pragma mark - UIPopoverPresentationControllerDelegate
- - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
- return UIModalPresentationNone;
- }
- @end
|