From 748e354d542e02f6d00d59d0b4201b9440bf8594 Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Wed, 10 Feb 2016 17:36:31 -0400 Subject: [PATCH 1/9] Adds a vertical padding property for images --- CRToast/CRToastConfig.h | 1 + CRToast/CRToastConfig.m | 8 ++++++++ CRToast/CRToastView.m | 7 ++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CRToast/CRToastConfig.h b/CRToast/CRToastConfig.h index 85e6cbca..8cd9f2a7 100644 --- a/CRToast/CRToastConfig.h +++ b/CRToast/CRToastConfig.h @@ -400,6 +400,7 @@ extern NSString *const kCRToastCaptureDefaultWindowKey; @property (nonatomic, readonly) CRToastType notificationType; @property (nonatomic, assign) CGFloat preferredHeight; @property (nonatomic, assign) CGFloat preferredPadding; +@property (nonatomic, assign) CGFloat verticalImagePadding; @property (nonatomic, readonly) CRToastPresentationType presentationType; @property (nonatomic, readonly) BOOL displayUnderStatusBar; @property (nonatomic, readonly) BOOL shouldKeepNavigationBarBorder; diff --git a/CRToast/CRToastConfig.m b/CRToast/CRToastConfig.m index 8b683e33..0c8deee9 100644 --- a/CRToast/CRToastConfig.m +++ b/CRToast/CRToastConfig.m @@ -220,6 +220,7 @@ + (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType) NSString *const kCRToastImageContentModeKey = @"kCRToastImageContentModeKey"; NSString *const kCRToastImageAlignmentKey = @"kCRToastImageAlignmentKey"; NSString *const kCRToastImageTintKey = @"kCRToastImageTintKey"; +NSString *const kCRToastImageVerticalPadding = @"kCRToastImageVerticalPadding"; NSString *const kCRToastShowActivityIndicatorKey = @"kCRToastShowActivityIndicatorKey"; NSString *const kCRToastActivityIndicatorViewStyleKey = @"kCRToastActivityIndicatorViewStyleKey"; NSString *const kCRToastActivityIndicatorAlignmentKey = @"kCRToastActivityIndicatorAlignmentKey"; @@ -277,6 +278,7 @@ + (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType) static UIViewContentMode kCRImageContentModeDefault = UIViewContentModeCenter; static CRToastAccessoryViewAlignment kCRImageAlignmentDefault = CRToastAccessoryViewAlignmentLeft; static UIColor * kCRImageTintDefault = nil; +static CGFloat kCRImageVerticalPadding = 0; static BOOL kCRShowActivityIndicatorDefault = NO; static UIActivityIndicatorViewStyle kCRActivityIndicatorViewStyleDefault = UIActivityIndicatorViewStyleWhite; static CRToastAccessoryViewAlignment kCRActivityIndicatorAlignmentDefault = CRToastAccessoryViewAlignmentLeft; @@ -546,6 +548,12 @@ - (CGFloat)preferredPadding { kCRNotificationPreferredPaddingDefault; } +- (CGFloat)verticalImagePadding { + return _options[kCRToastImageVerticalPadding] ? + [_options[kCRToastImageVerticalPadding] floatValue] : + kCRImageVerticalPadding; +} + - (CRToastPresentationType)presentationType { return _options[kCRToastNotificationPresentationTypeKey] ? [self.options[kCRToastNotificationPresentationTypeKey] integerValue] : diff --git a/CRToast/CRToastView.m b/CRToast/CRToastView.m index 8a9518de..7b6ed976 100644 --- a/CRToast/CRToastView.m +++ b/CRToast/CRToastView.m @@ -130,7 +130,8 @@ - (void)layoutSubviews { CGRect contentFrame = self.bounds; CGSize imageSize = self.imageView.image.size; CGFloat preferredPadding = self.toast.preferredPadding; - + CGFloat verticalImagePadding = self.toast.verticalImagePadding; + CGFloat statusBarYOffset = self.toast.displayUnderStatusBar ? (CRGetStatusBarHeight()+CRStatusBarViewUnderStatusBarYOffsetAdjustment) : 0; contentFrame.size.height = CGRectGetHeight(contentFrame) - statusBarYOffset; @@ -138,13 +139,13 @@ - (void)layoutSubviews { CGFloat imageXOffset = CRImageViewFrameXOffsetForAlignment(self.toast.imageAlignment, preferredPadding, contentFrame.size); self.imageView.frame = CGRectMake(imageXOffset, - statusBarYOffset, + statusBarYOffset+verticalImagePadding, imageSize.width == 0 ? 0 : CGRectGetHeight(contentFrame), imageSize.height == 0 ? 0 : - CGRectGetHeight(contentFrame)); + CGRectGetHeight(contentFrame) - (verticalImagePadding*2)); CGFloat imageWidth = imageSize.width == 0 ? 0 : CGRectGetMaxX(_imageView.frame); CGFloat x = CRContentXOffsetForViewAlignmentAndWidth(self.toast.imageAlignment, imageXOffset, imageWidth, preferredPadding); From e3f31d9876bf5f25c8aa1568a5f4834c61b7ff2b Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Wed, 10 Feb 2016 17:40:48 -0400 Subject: [PATCH 2/9] Refactor for consistency with existing code --- CRToast/CRToastConfig.h | 2 +- CRToast/CRToastConfig.m | 12 ++++++------ CRToast/CRToastView.m | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CRToast/CRToastConfig.h b/CRToast/CRToastConfig.h index 8cd9f2a7..ace101ad 100644 --- a/CRToast/CRToastConfig.h +++ b/CRToast/CRToastConfig.h @@ -400,7 +400,6 @@ extern NSString *const kCRToastCaptureDefaultWindowKey; @property (nonatomic, readonly) CRToastType notificationType; @property (nonatomic, assign) CGFloat preferredHeight; @property (nonatomic, assign) CGFloat preferredPadding; -@property (nonatomic, assign) CGFloat verticalImagePadding; @property (nonatomic, readonly) CRToastPresentationType presentationType; @property (nonatomic, readonly) BOOL displayUnderStatusBar; @property (nonatomic, readonly) BOOL shouldKeepNavigationBarBorder; @@ -439,6 +438,7 @@ extern NSString *const kCRToastCaptureDefaultWindowKey; @property (nonatomic, readonly) UIViewContentMode imageContentMode; @property (nonatomic, readonly) CRToastAccessoryViewAlignment imageAlignment; @property (nonatomic, readonly) UIColor *imageTint; +@property (nonatomic, readonly) CGFloat imageVerticalPadding; @property (nonatomic, readonly) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (nonatomic, readonly) CRToastAccessoryViewAlignment activityViewAlignment; @property (nonatomic, readonly) BOOL showActivityIndicator; diff --git a/CRToast/CRToastConfig.m b/CRToast/CRToastConfig.m index 0c8deee9..c6a25f34 100644 --- a/CRToast/CRToastConfig.m +++ b/CRToast/CRToastConfig.m @@ -548,12 +548,6 @@ - (CGFloat)preferredPadding { kCRNotificationPreferredPaddingDefault; } -- (CGFloat)verticalImagePadding { - return _options[kCRToastImageVerticalPadding] ? - [_options[kCRToastImageVerticalPadding] floatValue] : - kCRImageVerticalPadding; -} - - (CRToastPresentationType)presentationType { return _options[kCRToastNotificationPresentationTypeKey] ? [self.options[kCRToastNotificationPresentationTypeKey] integerValue] : @@ -708,6 +702,12 @@ - (UIColor *)imageTint { return _options[kCRToastImageTintKey] ?: kCRImageTintDefault; } +- (CGFloat)imageVericalPadding { + return _options[kCRToastImageVerticalPadding] ? + [_options[kCRToastImageVerticalPadding] floatValue] : + kCRImageVerticalPadding; +} + - (BOOL)showActivityIndicator { return _options[kCRToastShowActivityIndicatorKey] ? [_options[kCRToastShowActivityIndicatorKey] boolValue] : kCRShowActivityIndicatorDefault; } diff --git a/CRToast/CRToastView.m b/CRToast/CRToastView.m index 7b6ed976..2cdbff56 100644 --- a/CRToast/CRToastView.m +++ b/CRToast/CRToastView.m @@ -130,7 +130,7 @@ - (void)layoutSubviews { CGRect contentFrame = self.bounds; CGSize imageSize = self.imageView.image.size; CGFloat preferredPadding = self.toast.preferredPadding; - CGFloat verticalImagePadding = self.toast.verticalImagePadding; + CGFloat imageVerticalPadding = self.toast.imageVerticalPadding; CGFloat statusBarYOffset = self.toast.displayUnderStatusBar ? (CRGetStatusBarHeight()+CRStatusBarViewUnderStatusBarYOffsetAdjustment) : 0; contentFrame.size.height = CGRectGetHeight(contentFrame) - statusBarYOffset; @@ -139,13 +139,13 @@ - (void)layoutSubviews { CGFloat imageXOffset = CRImageViewFrameXOffsetForAlignment(self.toast.imageAlignment, preferredPadding, contentFrame.size); self.imageView.frame = CGRectMake(imageXOffset, - statusBarYOffset+verticalImagePadding, + statusBarYOffset+imageVerticalPadding, imageSize.width == 0 ? 0 : CGRectGetHeight(contentFrame), imageSize.height == 0 ? 0 : - CGRectGetHeight(contentFrame) - (verticalImagePadding*2)); + CGRectGetHeight(contentFrame) - (imageVerticalPadding*2)); CGFloat imageWidth = imageSize.width == 0 ? 0 : CGRectGetMaxX(_imageView.frame); CGFloat x = CRContentXOffsetForViewAlignmentAndWidth(self.toast.imageAlignment, imageXOffset, imageWidth, preferredPadding); From 3f85ed85254fcf8b1f3f5746684bb57029d18280 Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Wed, 10 Feb 2016 17:47:13 -0400 Subject: [PATCH 3/9] Adds support for rounded images --- CRToast/CRToastConfig.h | 1 + CRToast/CRToastConfig.m | 8 ++++++++ CRToast/CRToastView.m | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CRToast/CRToastConfig.h b/CRToast/CRToastConfig.h index ace101ad..d9ac3aa3 100644 --- a/CRToast/CRToastConfig.h +++ b/CRToast/CRToastConfig.h @@ -439,6 +439,7 @@ extern NSString *const kCRToastCaptureDefaultWindowKey; @property (nonatomic, readonly) CRToastAccessoryViewAlignment imageAlignment; @property (nonatomic, readonly) UIColor *imageTint; @property (nonatomic, readonly) CGFloat imageVerticalPadding; +@property (nonatomic, readonly) BOOL imageRounded; @property (nonatomic, readonly) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (nonatomic, readonly) CRToastAccessoryViewAlignment activityViewAlignment; @property (nonatomic, readonly) BOOL showActivityIndicator; diff --git a/CRToast/CRToastConfig.m b/CRToast/CRToastConfig.m index c6a25f34..8cdbe6e8 100644 --- a/CRToast/CRToastConfig.m +++ b/CRToast/CRToastConfig.m @@ -221,6 +221,7 @@ + (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType) NSString *const kCRToastImageAlignmentKey = @"kCRToastImageAlignmentKey"; NSString *const kCRToastImageTintKey = @"kCRToastImageTintKey"; NSString *const kCRToastImageVerticalPadding = @"kCRToastImageVerticalPadding"; +NSString *const kCRToastImageRounded = @"kCRToastImageRounded"; NSString *const kCRToastShowActivityIndicatorKey = @"kCRToastShowActivityIndicatorKey"; NSString *const kCRToastActivityIndicatorViewStyleKey = @"kCRToastActivityIndicatorViewStyleKey"; NSString *const kCRToastActivityIndicatorAlignmentKey = @"kCRToastActivityIndicatorAlignmentKey"; @@ -279,6 +280,7 @@ + (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType) static CRToastAccessoryViewAlignment kCRImageAlignmentDefault = CRToastAccessoryViewAlignmentLeft; static UIColor * kCRImageTintDefault = nil; static CGFloat kCRImageVerticalPadding = 0; +static BOOL kCRImageRounded = NO; static BOOL kCRShowActivityIndicatorDefault = NO; static UIActivityIndicatorViewStyle kCRActivityIndicatorViewStyleDefault = UIActivityIndicatorViewStyleWhite; static CRToastAccessoryViewAlignment kCRActivityIndicatorAlignmentDefault = CRToastAccessoryViewAlignmentLeft; @@ -708,6 +710,12 @@ - (CGFloat)imageVericalPadding { kCRImageVerticalPadding; } +- (BOOL)imageRounded { + return _options[kCRToastImageRounded] ? + [_options[kCRToastImageRounded] boolValue] : + kCRImageRounded; +} + - (BOOL)showActivityIndicator { return _options[kCRToastShowActivityIndicatorKey] ? [_options[kCRToastShowActivityIndicatorKey] boolValue] : kCRShowActivityIndicatorDefault; } diff --git a/CRToast/CRToastView.m b/CRToast/CRToastView.m index 2cdbff56..9249894e 100644 --- a/CRToast/CRToastView.m +++ b/CRToast/CRToastView.m @@ -131,6 +131,7 @@ - (void)layoutSubviews { CGSize imageSize = self.imageView.image.size; CGFloat preferredPadding = self.toast.preferredPadding; CGFloat imageVerticalPadding = self.toast.imageVerticalPadding; + BOOL imageRounded = self.toast.imageRounded; CGFloat statusBarYOffset = self.toast.displayUnderStatusBar ? (CRGetStatusBarHeight()+CRStatusBarViewUnderStatusBarYOffsetAdjustment) : 0; contentFrame.size.height = CGRectGetHeight(contentFrame) - statusBarYOffset; @@ -146,7 +147,11 @@ - (void)layoutSubviews { imageSize.height == 0 ? 0 : CGRectGetHeight(contentFrame) - (imageVerticalPadding*2)); - + if (imageRounded == YES) { + self.imageView.layer.cornerRadius = MIN(imageSize.height, imageSize.width)/2; + self.imageView.clipsToBounds = YES; + } + CGFloat imageWidth = imageSize.width == 0 ? 0 : CGRectGetMaxX(_imageView.frame); CGFloat x = CRContentXOffsetForViewAlignmentAndWidth(self.toast.imageAlignment, imageXOffset, imageWidth, preferredPadding); From fd30a81c90cf16301333f0f443c691ddde4e195e Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Wed, 10 Feb 2016 17:57:13 -0400 Subject: [PATCH 4/9] Appropiately exports the new keys --- CRToast/CRToastConfig.h | 10 ++++++++++ CRToast/CRToastConfig.m | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CRToast/CRToastConfig.h b/CRToast/CRToastConfig.h index d9ac3aa3..0acf5fbc 100644 --- a/CRToast/CRToastConfig.h +++ b/CRToast/CRToastConfig.h @@ -325,6 +325,16 @@ extern NSString *const kCRToastImageAlignmentKey; */ extern NSString *const kCRToastImageTintKey; +/** + The vertical padding used in this image. If supplied, it will create a padding of the specified amount of px above and below the image. + */ +extern NSString *const kCRToastImageVerticalPaddingKey; + +/** + The image style to use. If true is supplied, it will make the image render as a circle. Expects a BOOL + */ +extern NSString *const kCRToastImageRoundedKey; + /** BOOL setting whether the CRToast should show a loading indicator in the left image location. */ diff --git a/CRToast/CRToastConfig.m b/CRToast/CRToastConfig.m index 8cdbe6e8..8748907a 100644 --- a/CRToast/CRToastConfig.m +++ b/CRToast/CRToastConfig.m @@ -220,8 +220,8 @@ + (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType) NSString *const kCRToastImageContentModeKey = @"kCRToastImageContentModeKey"; NSString *const kCRToastImageAlignmentKey = @"kCRToastImageAlignmentKey"; NSString *const kCRToastImageTintKey = @"kCRToastImageTintKey"; -NSString *const kCRToastImageVerticalPadding = @"kCRToastImageVerticalPadding"; -NSString *const kCRToastImageRounded = @"kCRToastImageRounded"; +NSString *const kCRToastImageVerticalPaddingKey = @"kCRToastImageVerticalPadding"; +NSString *const kCRToastImageRoundedKey = @"kCRToastImageRounded"; NSString *const kCRToastShowActivityIndicatorKey = @"kCRToastShowActivityIndicatorKey"; NSString *const kCRToastActivityIndicatorViewStyleKey = @"kCRToastActivityIndicatorViewStyleKey"; NSString *const kCRToastActivityIndicatorAlignmentKey = @"kCRToastActivityIndicatorAlignmentKey"; @@ -279,8 +279,8 @@ + (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType) static UIViewContentMode kCRImageContentModeDefault = UIViewContentModeCenter; static CRToastAccessoryViewAlignment kCRImageAlignmentDefault = CRToastAccessoryViewAlignmentLeft; static UIColor * kCRImageTintDefault = nil; -static CGFloat kCRImageVerticalPadding = 0; -static BOOL kCRImageRounded = NO; +static CGFloat kCRImageVerticalPaddingDefault = 0; +static BOOL kCRImageRoundedDefault = NO; static BOOL kCRShowActivityIndicatorDefault = NO; static UIActivityIndicatorViewStyle kCRActivityIndicatorViewStyleDefault = UIActivityIndicatorViewStyleWhite; static CRToastAccessoryViewAlignment kCRActivityIndicatorAlignmentDefault = CRToastAccessoryViewAlignmentLeft; @@ -705,15 +705,15 @@ - (UIColor *)imageTint { } - (CGFloat)imageVericalPadding { - return _options[kCRToastImageVerticalPadding] ? - [_options[kCRToastImageVerticalPadding] floatValue] : - kCRImageVerticalPadding; + return _options[kCRToastImageVerticalPaddingKey] ? + [_options[kCRToastImageVerticalPaddingKey] floatValue] : + kCRImageVerticalPaddingDefault; } - (BOOL)imageRounded { - return _options[kCRToastImageRounded] ? - [_options[kCRToastImageRounded] boolValue] : - kCRImageRounded; + return _options[kCRToastImageRoundedKey] ? + [_options[kCRToastImageRoundedKey] boolValue] : + kCRImageRoundedDefault; } - (BOOL)showActivityIndicator { From e73d8f5f9a22b7c1746d88685356ed82464ab43e Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Thu, 11 Feb 2016 16:38:53 -0400 Subject: [PATCH 5/9] Adds the rounded image notification key --- CRToast/CRToastConfig.m | 2 + Example/CRToastDemo.xcodeproj/project.pbxproj | 6 +- .../AppIcon.appiconset/Contents.json | 15 ++ .../CRToastDemo/Images.xcassets/Contents.json | 6 + .../test_picture.imageset/Contents.json | 21 +++ .../test_picture.imageset/Unknown.png | Bin 0 -> 2319 bytes Example/CRToastDemo/MainViewController.m | 6 +- Example/CRToastDemo/MainViewController.xib | 156 +++++++----------- 8 files changed, 112 insertions(+), 100 deletions(-) create mode 100644 Example/CRToastDemo/Images.xcassets/Contents.json create mode 100644 Example/CRToastDemo/Images.xcassets/test_picture.imageset/Contents.json create mode 100644 Example/CRToastDemo/Images.xcassets/test_picture.imageset/Unknown.png diff --git a/CRToast/CRToastConfig.m b/CRToast/CRToastConfig.m index 8748907a..e554be7c 100644 --- a/CRToast/CRToastConfig.m +++ b/CRToast/CRToastConfig.m @@ -355,6 +355,7 @@ + (void)initialize { kCRToastImageKey : NSStringFromClass([UIImage class]), kCRToastImageContentModeKey : NSStringFromClass([@(kCRImageContentModeDefault) class]), kCRToastImageAlignmentKey : NSStringFromClass([@(kCRImageAlignmentDefault) class]), + kCRToastImageRoundedKey : NSStringFromClass([@(kCRImageRoundedDefault) class]), kCRToastImageTintKey : NSStringFromClass([UIColor class]), kCRToastShowActivityIndicatorKey : NSStringFromClass([@(kCRShowActivityIndicatorDefault) class]), kCRToastActivityIndicatorViewStyleKey : NSStringFromClass([@(kCRActivityIndicatorViewStyleDefault) class]), @@ -430,6 +431,7 @@ + (void)setDefaultOptions:(NSDictionary*)defaultOptions { if (defaultOptions[kCRToastImageContentModeKey]) kCRImageContentModeDefault = [defaultOptions[kCRToastImageContentModeKey] integerValue]; if (defaultOptions[kCRToastImageAlignmentKey]) kCRImageAlignmentDefault = [defaultOptions[kCRToastImageAlignmentKey] integerValue]; if (defaultOptions[kCRToastImageTintKey]) kCRImageTintDefault = defaultOptions[kCRToastImageTintKey]; + if (defaultOptions[kCRToastImageRoundedKey]) kCRImageRoundedDefault = defaultOptions[kCRToastImageRoundedKey]; if (defaultOptions[kCRToastShowActivityIndicatorKey]) kCRShowActivityIndicatorDefault = [defaultOptions[kCRToastShowActivityIndicatorKey] boolValue]; if (defaultOptions[kCRToastActivityIndicatorViewStyleKey]) kCRActivityIndicatorViewStyleDefault = [defaultOptions[kCRToastActivityIndicatorViewStyleKey] integerValue]; if (defaultOptions[kCRToastActivityIndicatorAlignmentKey]) kCRActivityIndicatorAlignmentDefault = [defaultOptions[kCRToastActivityIndicatorAlignmentKey] integerValue]; diff --git a/Example/CRToastDemo.xcodeproj/project.pbxproj b/Example/CRToastDemo.xcodeproj/project.pbxproj index 3b42b806..fb9dcc3e 100644 --- a/Example/CRToastDemo.xcodeproj/project.pbxproj +++ b/Example/CRToastDemo.xcodeproj/project.pbxproj @@ -197,7 +197,7 @@ ORGANIZATIONNAME = "Collin Ruffenach"; TargetAttributes = { 5E2FFB5218367C01003333F8 = { - DevelopmentTeam = 7AM27DZVQU; + DevelopmentTeam = XYZ9TSFRN2; }; }; }; @@ -384,7 +384,7 @@ INFOPLIST_FILE = "CRToastDemo/CRToastDemo-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_BUNDLE_IDENTIFIER = CRToastDemo.self; PRODUCT_NAME = CRToastDemo; PROVISIONING_PROFILE = ""; RUN_CLANG_STATIC_ANALYZER = YES; @@ -409,7 +409,7 @@ INFOPLIST_FILE = "CRToastDemo/CRToastDemo-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_BUNDLE_IDENTIFIER = CRToastDemo.self; PRODUCT_NAME = CRToastDemo; PROVISIONING_PROFILE = ""; RUN_CLANG_STATIC_ANALYZER = YES; diff --git a/Example/CRToastDemo/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/CRToastDemo/Images.xcassets/AppIcon.appiconset/Contents.json index b7f3352e..eeea76c2 100644 --- a/Example/CRToastDemo/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/CRToastDemo/Images.xcassets/AppIcon.appiconset/Contents.json @@ -5,11 +5,21 @@ "size" : "29x29", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "60x60", @@ -49,6 +59,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/Example/CRToastDemo/Images.xcassets/Contents.json b/Example/CRToastDemo/Images.xcassets/Contents.json new file mode 100644 index 00000000..da4a164c --- /dev/null +++ b/Example/CRToastDemo/Images.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/CRToastDemo/Images.xcassets/test_picture.imageset/Contents.json b/Example/CRToastDemo/Images.xcassets/test_picture.imageset/Contents.json new file mode 100644 index 00000000..614c6ce4 --- /dev/null +++ b/Example/CRToastDemo/Images.xcassets/test_picture.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "Unknown.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/CRToastDemo/Images.xcassets/test_picture.imageset/Unknown.png b/Example/CRToastDemo/Images.xcassets/test_picture.imageset/Unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..e9dbfb52aedd6800606d3c5e2bfef79e40eeb6f3 GIT binary patch literal 2319 zcmV+q3GnubP)}0Q&m+_V)Jh@bKyB>Fw?9^YinTmX_b&-`CgIXlQ7=ySs65ak#j+Mn*=arl!r! z&8)1fPft%XGc$aAd^$QhKtMp9ot-T$Emc)jkB^TX9UX>-hQh+aU0q!!CMFXT6Qa%| zS^xkDVM#~&u0q$jb!cg(b^$ij$fhm=Sph)f4T@xq=nCln4o`;U zd@{fkc`0Y?@{!dU9BGKfDd^o1$8_Zsh zV{d{xA5vx*hU3_d!)_l9T68`6rn(}G2U*RqA}?;9r<0Dbv&*h-S(+iisV&@eOgP5x z9>8_H!KVi?)NjFQuS88mAmeLUH42C>JtUpdcM!VIGp zyL0~`;4o1#o>ZF`p?X_*CLq6@k5|0n4t@qfd+IZRo$eQ&<9WFjXrL)i)`ly)A+Ju+{lX+5RMR}~6D#~MR!G{sYz z!?ZZ{NrS6AMMxIP-4mA9x+EGwgE_)@vr#n7%6m+c7&EBEqR~nnEHPqNG-;8uM?8rk zR|Ohh%RT%Uk~OayKD6(IWt%mcHD!zWDr*i5`!oq1U|puAv!1~ucD07@?!HM<57*eu z>NSL#D~e{ZgZ3Qk(hOmXon1JbuKj6<(|jr&xjU9I46CWMbSB=5RXSrqew;}WQ5J(-XikIR3 z1xxfCe)*^LXAjBr7pi)mf@@m-ya-c!QO_~xjo%JKXUzTrq`qRAS8%yss0Hz%{!^ltJzIL|a^k4!NDltK8!X%;)dM;QJ*r9FtQ z1&C7dV8hhEAAC3^fcw6Mk|9E5+IG9vQQTi=_)vGyzt;*RLk19xcXi6VE1a}cvXBIC zoOuODq$TuTe8)Ep)t$Wou~~f$afuO2fbV8Xz?~s$rOx9+qC=v$iHgOfA>@RXF=Hzw)%{y%Tk_8j_PBa{EwJ11;tw|?B} zp}RB245pBg`D%Sf<0)`qVK)u69kqVEHubQNg{G;*&a@0{N6Gq)r762Ll1T~qRsB(W zt5M&psF+tnTa7XZXcBV#){JFFt zO-9Of4rqkG&B9e1eDG{C`VLum7cd~rfEYRcKFTwR)p&TQp}{)o*ro@*(TpfIc2VRD zb!hBfwC;Fcwc7TP^I99tHDQ8_geeMFS#kj8X%K{hinbFdnX5*i!hgh(rU!xRO6(yx z$tFG$8_hu#OSn{tEp~8sQDFopfsBuww!9ooLQ)Sf@?NjGJK;@2mt9*9%{5I4t>*<8 z#onXYtu*BWnrK0Xy(uG|#>IIBsA$XkO$0rtOS0 z=V;m6$FK+ORu3~NR3S<>3sTG>iRVuBj-x%6ll1p!;{QjPVBVp6SZ1mD7ReT&@I-t` zijySvb|I8nIjSz)R>zYp^|_HGi*#5Cx-g5WM{F_gj)lr$;7bw;Qypj7>6$hb)p#QG z3n(se80{PH5Fh=4GykkpwKCoA^1;X^K506)dI@S @property (weak, nonatomic) IBOutlet UISlider *imageTintSlider; @property (weak, nonatomic) IBOutlet UISwitch *showImageSwitch; +@property (weak, nonatomic) IBOutlet UISwitch *roundedImageSwitch; @property (weak, nonatomic) IBOutlet UISwitch *showActivityIndicatorSwitch; @property (weak, nonatomic) IBOutlet UISwitch *coverNavBarSwitch; @property (weak, nonatomic) IBOutlet UISwitch *slideOverSwitch; @@ -217,9 +218,10 @@ - (NSDictionary*)options { kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeFromSegmentedControl(_outAnimationTypeSegmentedControl)), kCRToastAnimationInDirectionKey : @(self.segFromDirection.selectedSegmentIndex), kCRToastAnimationOutDirectionKey : @(self.segToDirection.selectedSegmentIndex), - kCRToastNotificationPreferredPaddingKey : @(self.sliderPadding.value)} mutableCopy]; + kCRToastNotificationPreferredPaddingKey : @(self.sliderPadding.value), + kCRToastImageRoundedKey : @(self.roundedImageSwitch.on)} mutableCopy]; if (self.showImageSwitch.on) { - options[kCRToastImageKey] = [UIImage imageNamed:@"alert_icon.png"]; + options[kCRToastImageKey] = [UIImage imageNamed:@"test_picture"]; options[kCRToastImageAlignmentKey] = @(CRToastViewAlignmentForSegmentedControl(self.imageAlignmentSegmentedControl)); } diff --git a/Example/CRToastDemo/MainViewController.xib b/Example/CRToastDemo/MainViewController.xib index 0afee8b6..37f11b73 100644 --- a/Example/CRToastDemo/MainViewController.xib +++ b/Example/CRToastDemo/MainViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -20,6 +20,7 @@ + @@ -47,11 +48,10 @@ - + - @@ -61,7 +61,6 @@ - @@ -94,7 +91,6 @@ - @@ -107,14 +103,12 @@ - - - - @@ -505,12 +473,14 @@ + + @@ -521,6 +491,7 @@ + @@ -545,6 +516,8 @@ + + @@ -557,12 +530,13 @@ - + + @@ -573,7 +547,6 @@ - @@ -584,7 +557,6 @@ - @@ -606,7 +578,6 @@ - @@ -622,9 +593,4 @@ - - - - - From 22f1b05b595ec7df426412083de9a9e4b64965c5 Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Thu, 11 Feb 2016 17:11:49 -0400 Subject: [PATCH 6/9] Adds and links up the verticalPadding slider --- CRToast/CRToastView.m | 32 +++++++---- Example/CRToastDemo/MainViewController.m | 10 ++++ Example/CRToastDemo/MainViewController.xib | 64 +++++++++++++++++----- 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/CRToast/CRToastView.m b/CRToast/CRToastView.m index 9249894e..bb894494 100644 --- a/CRToast/CRToastView.m +++ b/CRToast/CRToastView.m @@ -139,17 +139,29 @@ - (void)layoutSubviews { self.backgroundView.frame = self.bounds; CGFloat imageXOffset = CRImageViewFrameXOffsetForAlignment(self.toast.imageAlignment, preferredPadding, contentFrame.size); - self.imageView.frame = CGRectMake(imageXOffset, - statusBarYOffset+imageVerticalPadding, - imageSize.width == 0 ? - 0 : - CGRectGetHeight(contentFrame), - imageSize.height == 0 ? - 0 : - CGRectGetHeight(contentFrame) - (imageVerticalPadding*2)); + + + if (imageRounded == YES) { - self.imageView.layer.cornerRadius = MIN(imageSize.height, imageSize.width)/2; - self.imageView.clipsToBounds = YES; + // Force the image to be a square + CGFloat dimension = CGRectGetHeight(contentFrame); + self.imageView.frame = CGRectMake(imageXOffset, + statusBarYOffset+imageVerticalPadding, + dimension, + dimension - (imageVerticalPadding*2)); + + // Set it as rounded + self.imageView.layer.cornerRadius = dimension/2; + self.imageView.clipsToBounds = YES; + } else { + self.imageView.frame = CGRectMake(imageXOffset, + statusBarYOffset+imageVerticalPadding, + imageSize.width == 0 ? + 0 : + CGRectGetHeight(contentFrame), + imageSize.height == 0 ? + 0 : + CGRectGetHeight(contentFrame) - (imageVerticalPadding*2)); } CGFloat imageWidth = imageSize.width == 0 ? 0 : CGRectGetMaxX(_imageView.frame); diff --git a/Example/CRToastDemo/MainViewController.m b/Example/CRToastDemo/MainViewController.m index a550f6ad..2784679e 100644 --- a/Example/CRToastDemo/MainViewController.m +++ b/Example/CRToastDemo/MainViewController.m @@ -28,6 +28,8 @@ @interface MainViewController () @property (weak, nonatomic) IBOutlet UISwitch *imageTintEnabledSwitch; @property (weak, nonatomic) IBOutlet UISlider *imageTintSlider; +@property (weak, nonatomic) IBOutlet UISlider *imageVerticalPaddingSlider; +@property (weak, nonatomic) IBOutlet UILabel *lblImageVerticalPadding; @property (weak, nonatomic) IBOutlet UISwitch *showImageSwitch; @property (weak, nonatomic) IBOutlet UISwitch *roundedImageSwitch; @@ -133,10 +135,18 @@ - (IBAction)sliderImageTintChanged:(UISlider *)sender { [self updateImageTintSwitch]; } +- (IBAction)sliderImageVerticalPaddingChanged:(UISlider *)sender { + [self updateVerticalPaddingLabel]; +} + - (void)updateImageTintSwitch { self.imageTintEnabledSwitch.onTintColor = [UIColor colorWithHue:self.imageTintSlider.value saturation:1.0 brightness:1.0 alpha:1.0]; } +- (void)updateVerticalPaddingLabel { + self.lblImageVerticalPadding.text = [NSString stringWithFormat:@"%d", (int)roundf(self.imageVerticalPaddingSlider.value)]; +} + - (IBAction)statusBarChanged:(UISwitch *)sender { [self setNeedsStatusBarAppearanceUpdate]; } diff --git a/Example/CRToastDemo/MainViewController.xib b/Example/CRToastDemo/MainViewController.xib index 37f11b73..b8d5dffb 100644 --- a/Example/CRToastDemo/MainViewController.xib +++ b/Example/CRToastDemo/MainViewController.xib @@ -15,8 +15,10 @@ + + @@ -41,14 +43,14 @@ - + - + - + @@ -125,6 +127,16 @@ + @@ -395,6 +407,25 @@ + + + + + + + + + + @@ -407,19 +438,18 @@ - + + + @@ -436,10 +466,12 @@ + + @@ -457,6 +489,7 @@ + @@ -490,10 +523,11 @@ + - + @@ -504,6 +538,7 @@ + @@ -512,6 +547,7 @@ + @@ -548,7 +584,7 @@ - + @@ -556,7 +592,7 @@ - + @@ -590,7 +626,7 @@ - + From 29f7567004362aed66116d8eddc32767b27e7274 Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Fri, 12 Feb 2016 08:20:54 -0400 Subject: [PATCH 7/9] Now correctly adds the imagepadding --- CRToast/CRToastConfig.m | 6 ++++-- CRToast/CRToastView.m | 1 + Example/CRToastDemo/MainViewController.m | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CRToast/CRToastConfig.m b/CRToast/CRToastConfig.m index e554be7c..198b436b 100644 --- a/CRToast/CRToastConfig.m +++ b/CRToast/CRToastConfig.m @@ -357,6 +357,7 @@ + (void)initialize { kCRToastImageAlignmentKey : NSStringFromClass([@(kCRImageAlignmentDefault) class]), kCRToastImageRoundedKey : NSStringFromClass([@(kCRImageRoundedDefault) class]), kCRToastImageTintKey : NSStringFromClass([UIColor class]), + kCRToastImageVerticalPaddingKey : NSStringFromClass([@(kCRImageVerticalPaddingDefault) class]), kCRToastShowActivityIndicatorKey : NSStringFromClass([@(kCRShowActivityIndicatorDefault) class]), kCRToastActivityIndicatorViewStyleKey : NSStringFromClass([@(kCRActivityIndicatorViewStyleDefault) class]), kCRToastActivityIndicatorAlignmentKey : NSStringFromClass([@(kCRActivityIndicatorAlignmentDefault) class]), @@ -431,7 +432,8 @@ + (void)setDefaultOptions:(NSDictionary*)defaultOptions { if (defaultOptions[kCRToastImageContentModeKey]) kCRImageContentModeDefault = [defaultOptions[kCRToastImageContentModeKey] integerValue]; if (defaultOptions[kCRToastImageAlignmentKey]) kCRImageAlignmentDefault = [defaultOptions[kCRToastImageAlignmentKey] integerValue]; if (defaultOptions[kCRToastImageTintKey]) kCRImageTintDefault = defaultOptions[kCRToastImageTintKey]; - if (defaultOptions[kCRToastImageRoundedKey]) kCRImageRoundedDefault = defaultOptions[kCRToastImageRoundedKey]; + if (defaultOptions[kCRToastImageRoundedKey]) kCRImageRoundedDefault = [defaultOptions[kCRToastImageRoundedKey] boolValue]; + if (defaultOptions[kCRToastImageVerticalPaddingKey]) kCRImageVerticalPaddingDefault = [defaultOptions [kCRToastImageVerticalPaddingKey] integerValue]; if (defaultOptions[kCRToastShowActivityIndicatorKey]) kCRShowActivityIndicatorDefault = [defaultOptions[kCRToastShowActivityIndicatorKey] boolValue]; if (defaultOptions[kCRToastActivityIndicatorViewStyleKey]) kCRActivityIndicatorViewStyleDefault = [defaultOptions[kCRToastActivityIndicatorViewStyleKey] integerValue]; if (defaultOptions[kCRToastActivityIndicatorAlignmentKey]) kCRActivityIndicatorAlignmentDefault = [defaultOptions[kCRToastActivityIndicatorAlignmentKey] integerValue]; @@ -706,7 +708,7 @@ - (UIColor *)imageTint { return _options[kCRToastImageTintKey] ?: kCRImageTintDefault; } -- (CGFloat)imageVericalPadding { +- (CGFloat)imageVerticalPadding { return _options[kCRToastImageVerticalPaddingKey] ? [_options[kCRToastImageVerticalPaddingKey] floatValue] : kCRImageVerticalPaddingDefault; diff --git a/CRToast/CRToastView.m b/CRToast/CRToastView.m index bb894494..c06f2900 100644 --- a/CRToast/CRToastView.m +++ b/CRToast/CRToastView.m @@ -131,6 +131,7 @@ - (void)layoutSubviews { CGSize imageSize = self.imageView.image.size; CGFloat preferredPadding = self.toast.preferredPadding; CGFloat imageVerticalPadding = self.toast.imageVerticalPadding; + NSLog(@"vertical padding: %f", imageVerticalPadding); // TODO: Remove BOOL imageRounded = self.toast.imageRounded; CGFloat statusBarYOffset = self.toast.displayUnderStatusBar ? (CRGetStatusBarHeight()+CRStatusBarViewUnderStatusBarYOffsetAdjustment) : 0; diff --git a/Example/CRToastDemo/MainViewController.m b/Example/CRToastDemo/MainViewController.m index 2784679e..67841afe 100644 --- a/Example/CRToastDemo/MainViewController.m +++ b/Example/CRToastDemo/MainViewController.m @@ -229,7 +229,8 @@ - (NSDictionary*)options { kCRToastAnimationInDirectionKey : @(self.segFromDirection.selectedSegmentIndex), kCRToastAnimationOutDirectionKey : @(self.segToDirection.selectedSegmentIndex), kCRToastNotificationPreferredPaddingKey : @(self.sliderPadding.value), - kCRToastImageRoundedKey : @(self.roundedImageSwitch.on)} mutableCopy]; + kCRToastImageRoundedKey : @(self.roundedImageSwitch.on), + kCRToastImageVerticalPaddingKey : @(self.imageVerticalPaddingSlider.value)} mutableCopy]; if (self.showImageSwitch.on) { options[kCRToastImageKey] = [UIImage imageNamed:@"test_picture"]; options[kCRToastImageAlignmentKey] = @(CRToastViewAlignmentForSegmentedControl(self.imageAlignmentSegmentedControl)); From 3108a8fc314e4d6f0a2c539dd1bc8cecfc095db6 Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Fri, 12 Feb 2016 08:29:48 -0400 Subject: [PATCH 8/9] Fixes a bug where a round imageview would change it's size on dismissal --- CRToast/CRToastView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRToast/CRToastView.m b/CRToast/CRToastView.m index c06f2900..1aa094de 100644 --- a/CRToast/CRToastView.m +++ b/CRToast/CRToastView.m @@ -145,11 +145,11 @@ - (void)layoutSubviews { if (imageRounded == YES) { // Force the image to be a square - CGFloat dimension = CGRectGetHeight(contentFrame); + CGFloat dimension = self.imageView.frame.size.height > 0 ? self.imageView.frame.size.height : CGRectGetHeight(contentFrame) - imageVerticalPadding*2; self.imageView.frame = CGRectMake(imageXOffset, statusBarYOffset+imageVerticalPadding, dimension, - dimension - (imageVerticalPadding*2)); + dimension); // Set it as rounded self.imageView.layer.cornerRadius = dimension/2; From 85a7e72941855c5d966994c6539af36b683e14df Mon Sep 17 00:00:00 2001 From: Miguel Saiz Date: Fri, 12 Feb 2016 09:41:08 -0400 Subject: [PATCH 9/9] Improves documentation --- CRToast/CRToastConfig.h | 5 +++++ CRToast/CRToastView.m | 3 +++ Example/CRToastDemo.xcodeproj/project.pbxproj | 5 ----- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CRToast/CRToastConfig.h b/CRToast/CRToastConfig.h index 0acf5fbc..97e3f792 100644 --- a/CRToast/CRToastConfig.h +++ b/CRToast/CRToastConfig.h @@ -327,11 +327,16 @@ extern NSString *const kCRToastImageTintKey; /** The vertical padding used in this image. If supplied, it will create a padding of the specified amount of px above and below the image. + + @note Providing `kCRToastImageContentModeKey` a UIViewContentMode.ScaleToFit is recommended when using this property. */ extern NSString *const kCRToastImageVerticalPaddingKey; /** The image style to use. If true is supplied, it will make the image render as a circle. Expects a BOOL + + + @note Providing `kCRToastImageContentModeKey` a UIViewContentMode.ScaleToFit is recommended when using this property. */ extern NSString *const kCRToastImageRoundedKey; diff --git a/CRToast/CRToastView.m b/CRToast/CRToastView.m index 1aa094de..3e60fca2 100644 --- a/CRToast/CRToastView.m +++ b/CRToast/CRToastView.m @@ -163,6 +163,9 @@ - (void)layoutSubviews { imageSize.height == 0 ? 0 : CGRectGetHeight(contentFrame) - (imageVerticalPadding*2)); + + // Only clip to bounds when the image has padding + self.imageView.clipsToBounds = imageVerticalPadding > 0; } CGFloat imageWidth = imageSize.width == 0 ? 0 : CGRectGetMaxX(_imageView.frame); diff --git a/Example/CRToastDemo.xcodeproj/project.pbxproj b/Example/CRToastDemo.xcodeproj/project.pbxproj index fb9dcc3e..ec28c352 100644 --- a/Example/CRToastDemo.xcodeproj/project.pbxproj +++ b/Example/CRToastDemo.xcodeproj/project.pbxproj @@ -195,11 +195,6 @@ attributes = { LastUpgradeCheck = 0700; ORGANIZATIONNAME = "Collin Ruffenach"; - TargetAttributes = { - 5E2FFB5218367C01003333F8 = { - DevelopmentTeam = XYZ9TSFRN2; - }; - }; }; buildConfigurationList = 5E2FFB4E18367C01003333F8 /* Build configuration list for PBXProject "CRToastDemo" */; compatibilityVersion = "Xcode 3.2";