From fef67df7a57373b6db821f503ca07b8c136dee64 Mon Sep 17 00:00:00 2001 From: Mati Bot Date: Sun, 6 Sep 2015 16:55:12 +0300 Subject: [PATCH] * Added like/nope font size, defaults to 48.f --- .../Internal/Views/UIView+MDCBorderedLabel.h | 1 + .../Internal/Views/UIView+MDCBorderedLabel.m | 9 +++++--- .../Options/MDCSwipeToChooseViewOptions.h | 22 ++++++++++++++----- .../Options/MDCSwipeToChooseViewOptions.m | 6 +++-- .../Public/Views/MDCSwipeToChooseView.m | 10 +++++---- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/MDCSwipeToChoose/Internal/Views/UIView+MDCBorderedLabel.h b/MDCSwipeToChoose/Internal/Views/UIView+MDCBorderedLabel.h index 326de31..3711a7d 100644 --- a/MDCSwipeToChoose/Internal/Views/UIView+MDCBorderedLabel.h +++ b/MDCSwipeToChoose/Internal/Views/UIView+MDCBorderedLabel.h @@ -28,6 +28,7 @@ - (void)constructBorderedLabelWithText:(NSString *)text color:(UIColor *)color + size:(CGFloat)size angle:(CGFloat)angle; @end diff --git a/MDCSwipeToChoose/Internal/Views/UIView+MDCBorderedLabel.m b/MDCSwipeToChoose/Internal/Views/UIView+MDCBorderedLabel.m index 9367fcc..1b138c0 100644 --- a/MDCSwipeToChoose/Internal/Views/UIView+MDCBorderedLabel.m +++ b/MDCSwipeToChoose/Internal/Views/UIView+MDCBorderedLabel.m @@ -30,19 +30,22 @@ @implementation UIView (MDCBorderedLabel) - (void)constructBorderedLabelWithText:(NSString *)text color:(UIColor *)color + size:(CGFloat)size angle:(CGFloat)angle { + + self.layer.borderColor = color.CGColor; self.layer.borderWidth = 5.f; self.layer.cornerRadius = 10.f; - + UILabel *label = [[UILabel alloc] initWithFrame:self.bounds]; label.text = [text uppercaseString]; label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" - size:48.f]; + size:size]; label.textColor = color; [self addSubview:label]; - + self.transform = CGAffineTransformRotate(CGAffineTransformIdentity, MDCDegreesToRadians(angle)); } diff --git a/MDCSwipeToChoose/Public/Options/MDCSwipeToChooseViewOptions.h b/MDCSwipeToChoose/Public/Options/MDCSwipeToChooseViewOptions.h index b312df5..4087afd 100644 --- a/MDCSwipeToChoose/Public/Options/MDCSwipeToChooseViewOptions.h +++ b/MDCSwipeToChoose/Public/Options/MDCSwipeToChooseViewOptions.h @@ -48,8 +48,7 @@ */ @property (nonatomic, strong) UIColor *likedColor; -/*! - * The image used to displayed in the `likeView`. If this is present, it will take +/* The image used to displayed in the `likeView`. If this is present, it will take * precedence over the likeText */ @property (nonatomic, strong) UIImage *likedImage; @@ -60,6 +59,12 @@ */ @property (nonatomic, assign) CGFloat likedRotationAngle; +/*! + * The size of the text in the `likedView`. A default value is provided in the + * `-init` method. + */ +@property (nonatomic, assign) CGFloat likedTextSize; + /*! * The text displayed in the `nopeView`. A default value is provided in the * `-init` method. @@ -73,16 +78,21 @@ @property (nonatomic, strong) UIColor *nopeColor; /*! - * The image used to displayed in the `nopeView`. If this is present, it will take - * precedence over the nopeText + * The rotation angle of the `nopeView`. A default value is provided in the + * `-init` method. + */ +@property (nonatomic, assign) CGFloat nopeRotationAngle; + +/* The image used to displayed in the `nopeView`. If this is present, it will take + * precedence over the likeText */ @property (nonatomic, strong) UIImage *nopeImage; /*! - * The rotation angle of the `nopeView`. A default value is provided in the + * The size of the text in the `nopeView`. A default value is provided in the * `-init` method. */ -@property (nonatomic, assign) CGFloat nopeRotationAngle; +@property (nonatomic, assign) CGFloat nopeTextSize; /*! * The distance, in pixels, that a view must be panned in order to constitue a selection. diff --git a/MDCSwipeToChoose/Public/Options/MDCSwipeToChooseViewOptions.m b/MDCSwipeToChoose/Public/Options/MDCSwipeToChooseViewOptions.m index fb79dc5..b09e17c 100644 --- a/MDCSwipeToChoose/Public/Options/MDCSwipeToChooseViewOptions.m +++ b/MDCSwipeToChoose/Public/Options/MDCSwipeToChooseViewOptions.m @@ -33,11 +33,13 @@ - (instancetype)init { _likedText = [NSLocalizedString(@"liked", nil) uppercaseString]; _likedColor = [UIColor colorWith8BitRed:29.f green:245.f blue:106.f alpha:1.f]; _likedRotationAngle = -15.f; - + _likedTextSize = 48.f; + _nopeText = [NSLocalizedString(@"nope", nil) uppercaseString]; _nopeColor = [UIColor colorWith8BitRed:247.f green:91.f blue:37.f alpha:1.f]; _nopeRotationAngle = 15.f; - + _nopeTextSize = 48.f; + _threshold = 100.f; } return self; diff --git a/MDCSwipeToChoose/Public/Views/MDCSwipeToChooseView.m b/MDCSwipeToChoose/Public/Views/MDCSwipeToChooseView.m index cbd9955..a061750 100644 --- a/MDCSwipeToChoose/Public/Views/MDCSwipeToChooseView.m +++ b/MDCSwipeToChoose/Public/Views/MDCSwipeToChooseView.m @@ -76,7 +76,7 @@ - (void)constructImageView { - (void)constructLikedView { CGFloat yOrigin = (self.options.likedImage ? MDCSwipeToChooseViewImageTopPadding : MDCSwipeToChooseViewTopPadding); - + CGRect frame = CGRectMake(MDCSwipeToChooseViewHorizontalPadding, yOrigin, CGRectGetMidX(self.imageView.bounds), @@ -89,6 +89,7 @@ - (void)constructLikedView { self.likedView = [[UIView alloc] initWithFrame:frame]; [self.likedView constructBorderedLabelWithText:self.options.likedText color:self.options.likedColor + size:self.options.likedTextSize angle:self.options.likedRotationAngle]; } self.likedView.alpha = 0.f; @@ -111,6 +112,7 @@ - (void)constructNopeView { self.nopeView = [[UIView alloc] initWithFrame:frame]; [self.nopeView constructBorderedLabelWithText:self.options.nopeText color:self.options.nopeColor + size:self.options.nopeTextSize angle:self.options.nopeRotationAngle]; } self.nopeView.alpha = 0.f; @@ -121,7 +123,7 @@ - (void)setupSwipeToChoose { MDCSwipeOptions *options = [MDCSwipeOptions new]; options.delegate = self.options.delegate; options.threshold = self.options.threshold; - + __block UIView *likedImageView = self.likedView; __block UIView *nopeImageView = self.nopeView; __weak MDCSwipeToChooseView *weakself = self; @@ -136,12 +138,12 @@ - (void)setupSwipeToChoose { likedImageView.alpha = state.thresholdRatio; nopeImageView.alpha = 0.f; } - + if (weakself.options.onPan) { weakself.options.onPan(state); } }; - + [self mdc_swipeToChooseSetup:options]; }