From 96cac442588cae21e97b7cc6aa70cc63f5de3bb4 Mon Sep 17 00:00:00 2001 From: Abuzar Amin Date: Fri, 8 May 2015 19:51:25 +0500 Subject: [PATCH] Added support for Right to left languages also added the option of message in case of success notice view --- NoticeView.xcodeproj/project.pbxproj | 12 ++ NoticeView/WBNoticeView/MyErrorNoticeView.h | 16 +++ NoticeView/WBNoticeView/MyErrorNoticeView.m | 143 +++++++++++++++++++ NoticeView/WBNoticeView/MySuccessNotice.h | 12 ++ NoticeView/WBNoticeView/MySuccessNotice.m | 147 ++++++++++++++++++++ NoticeView/WBNoticeView/WBNoticeView.h | 14 ++ 6 files changed, 344 insertions(+) create mode 100644 NoticeView/WBNoticeView/MyErrorNoticeView.h create mode 100644 NoticeView/WBNoticeView/MyErrorNoticeView.m create mode 100644 NoticeView/WBNoticeView/MySuccessNotice.h create mode 100644 NoticeView/WBNoticeView/MySuccessNotice.m diff --git a/NoticeView.xcodeproj/project.pbxproj b/NoticeView.xcodeproj/project.pbxproj index 876c547..c7f0ff7 100644 --- a/NoticeView.xcodeproj/project.pbxproj +++ b/NoticeView.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 250628781651F7DC00D3443E /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 250628771651F7DB00D3443E /* Default-568h@2x.png */; }; 3EA90DC617086FF70045E620 /* WBScrollViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EA90DC517086FF70045E620 /* WBScrollViewController.m */; }; + 47DC24E91AFD03200039192A /* MyErrorNoticeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 47DC24E61AFD03200039192A /* MyErrorNoticeView.m */; }; + 47DC24EA1AFD03200039192A /* MySuccessNotice.m in Sources */ = {isa = PBXBuildFile; fileRef = 47DC24E81AFD03200039192A /* MySuccessNotice.m */; }; 592BDDE915645BEE00B78820 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 592BDDE115645BEE00B78820 /* Default.png */; }; 592BDDEA15645BEE00B78820 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 592BDDE215645BEE00B78820 /* Default@2x.png */; }; 592BDDEB15645BEE00B78820 /* NoticeView.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 592BDDE415645BEE00B78820 /* NoticeView.bundle */; }; @@ -39,6 +41,10 @@ 250628771651F7DB00D3443E /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "../../Default-568h@2x.png"; sourceTree = ""; }; 3EA90DC417086FF70045E620 /* WBScrollViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WBScrollViewController.h; sourceTree = ""; }; 3EA90DC517086FF70045E620 /* WBScrollViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WBScrollViewController.m; sourceTree = ""; }; + 47DC24E51AFD03200039192A /* MyErrorNoticeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyErrorNoticeView.h; sourceTree = ""; }; + 47DC24E61AFD03200039192A /* MyErrorNoticeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyErrorNoticeView.m; sourceTree = ""; }; + 47DC24E71AFD03200039192A /* MySuccessNotice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MySuccessNotice.h; sourceTree = ""; }; + 47DC24E81AFD03200039192A /* MySuccessNotice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MySuccessNotice.m; sourceTree = ""; }; 592BDDE115645BEE00B78820 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; 592BDDE215645BEE00B78820 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; 592BDDE415645BEE00B78820 /* NoticeView.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = NoticeView.bundle; sourceTree = ""; }; @@ -108,6 +114,10 @@ 592BDDE315645BEE00B78820 /* WBNoticeView */ = { isa = PBXGroup; children = ( + 47DC24E51AFD03200039192A /* MyErrorNoticeView.h */, + 47DC24E61AFD03200039192A /* MyErrorNoticeView.m */, + 47DC24E71AFD03200039192A /* MySuccessNotice.h */, + 47DC24E81AFD03200039192A /* MySuccessNotice.m */, FE07240A16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.h */, FE07240B16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.m */, 746CBCFE1570A1D100B844B1 /* WBErrorNoticeView.h */, @@ -274,11 +284,13 @@ 592BDDED15645BEE00B78820 /* WBNoticeView.m in Sources */, 746CBD001570A1D100B844B1 /* WBErrorNoticeView.m in Sources */, 746CBD081570A8FA00B844B1 /* WBSuccessNoticeView.m in Sources */, + 47DC24E91AFD03200039192A /* MyErrorNoticeView.m in Sources */, 7492FA45157C8CD700FB834C /* WBBlueGradientView.m in Sources */, 7492FA46157C8CD700FB834C /* WBRedGradientView.m in Sources */, 748A6A59157D0B74003C7655 /* WBGrayGradientView.m in Sources */, 748A6A5D157D0D06003C7655 /* WBStickyNoticeView.m in Sources */, FED81FA916B97A1C00254985 /* WBNoticeOperation.m in Sources */, + 47DC24EA1AFD03200039192A /* MySuccessNotice.m in Sources */, FE07240C16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.m in Sources */, 3EA90DC617086FF70045E620 /* WBScrollViewController.m in Sources */, ); diff --git a/NoticeView/WBNoticeView/MyErrorNoticeView.h b/NoticeView/WBNoticeView/MyErrorNoticeView.h new file mode 100644 index 0000000..4faf35c --- /dev/null +++ b/NoticeView/WBNoticeView/MyErrorNoticeView.h @@ -0,0 +1,16 @@ +// +// MyErrorNoticeView.h +// +// +// Created by Abuzar Amin on 12/03/2015. + + +#import +#import "WBNoticeView.h" + + +@interface MyErrorNoticeView : WBNoticeView + ++ (MyErrorNoticeView *)errorNoticeInView:(UIView *)view title:(NSString *)title message:(NSString *)message languageDirection: (LanguageDirection) direction; + +@end diff --git a/NoticeView/WBNoticeView/MyErrorNoticeView.m b/NoticeView/WBNoticeView/MyErrorNoticeView.m new file mode 100644 index 0000000..323c243 --- /dev/null +++ b/NoticeView/WBNoticeView/MyErrorNoticeView.m @@ -0,0 +1,143 @@ +// +// MyErrorNoticeView.m + +// +// Created by Abuzar Amin on 12/03/2015. + +#import "MyErrorNoticeView.h" +#import "WBNoticeView+ForSubclassEyesOnly.h" +#import "WBRedGradientView.h" +@implementation MyErrorNoticeView + ++ (MyErrorNoticeView *)errorNoticeInView:(UIView *)view title:(NSString *)title message:(NSString *)message languageDirection: (LanguageDirection) direction +{ + MyErrorNoticeView *notice = [[MyErrorNoticeView alloc]initWithView:view title:title]; + + notice.message = message; + notice.sticky = NO; + notice.languageDirection = direction; + + return notice; +} + +- (void)show +{ + // Obtain the screen width + CGFloat viewWidth = self.view.bounds.size.width; + UIImageView *iconView ; + // Locate the images + NSString *path = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"NoticeView.bundle"]; + NSString *noticeIconImageName = [path stringByAppendingPathComponent:@"notice_error_icon.png"]; + + // Make and add the title label + float titleYOrigin = 10.0; + if (self.languageDirection == RightToLeft) + { + self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0 + (self.contentInset.left), titleYOrigin + (self.contentInset.top), viewWidth - 70.0 - (self.contentInset.right+self.contentInset.left) , 16.0)]; + self.titleLabel.textAlignment = NSTextAlignmentRight ; + + + self.messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(15 , 20.0 + 10.0 + (self.contentInset.top), viewWidth-70, 12.0)]; + self.messageLabel.textAlignment = NSTextAlignmentRight ; + + + iconView = [[UIImageView alloc]initWithFrame:CGRectMake(290.0, 10.0, 20.0, 30.0)]; + } + else{ + self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(55.0 + (self.contentInset.left), titleYOrigin + (self.contentInset.top), viewWidth - 70.0 - (self.contentInset.right+self.contentInset.left) , 16.0)]; + self.titleLabel.textAlignment = NSTextAlignmentLeft ; + // self.titleLabel.font = [DDTheme englishCustomFontWithBold:14.0] ; + self.titleLabel.font = [UIFont boldSystemFontOfSize:14.0]; + + self.messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(55.0 + (self.contentInset.left), 20.0 + 10.0 + (self.contentInset.top), viewWidth - 70.0 - (self.contentInset.right+self.contentInset.left), 12.0)]; + self.messageLabel.textAlignment = NSTextAlignmentLeft ; + // self.messageLabel.font = [DDTheme englishCustomFont:13.0] ; + self.messageLabel.font = [UIFont systemFontOfSize:13.0]; + iconView = [[UIImageView alloc]initWithFrame:CGRectMake(10.0, 10.0, 20.0, 30.0)]; + } + + // NSLog(@"titleLabelFrame: %@", NSStringFromCGRect(self.titleLabel.frame)); + // self.titleLabel.layer.borderWidth = 1; + // self.titleLabel.layer.borderColor = [UIColor greenColor].CGColor; + self.titleLabel.textColor = [UIColor whiteColor]; + self.titleLabel.shadowOffset = CGSizeMake(0.0, -1.0); + self.titleLabel.shadowColor = [UIColor blackColor]; + self.titleLabel.backgroundColor = [UIColor clearColor]; + self.titleLabel.text = self.title; + + // Make the message label + // [self.messageLabel.layer setBackgroundColor:[UIColor blackColor].CGColor] ; + //self.messageLabel.font = [DDTheme englishCustomFont:13.0]; + self.messageLabel.textColor = [UIColor colorWithRed:239.0/255.0 green:167.0/255.0 blue:163.0/255.0 alpha:1.0]; + self.messageLabel.backgroundColor = [UIColor clearColor]; + self.messageLabel.text = self.message; + + // Calculate the number of lines it'll take to display the text + NSInteger numberOfLines = [[self.messageLabel lines]count]; + self.messageLabel.numberOfLines = numberOfLines; + [self.messageLabel sizeToFit]; + CGFloat messageLabelHeight = self.messageLabel.frame.size.height; + + CGRect r = self.messageLabel.frame; + r.origin.y = self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height; + + float noticeViewHeight = 0.0; + double currOsVersion = [[[UIDevice currentDevice]systemVersion]doubleValue]; + if (currOsVersion >= 6.0f) { + noticeViewHeight = messageLabelHeight; + } else { + // Now we can determine the height of one line of text + r.size.height = self.messageLabel.frame.size.height * numberOfLines; + r.size.width = viewWidth - 70.0; + self.messageLabel.frame = r; + + // Calculate the notice view height + noticeViewHeight = 10.0; + if (numberOfLines > 1) { + noticeViewHeight += ((numberOfLines - 1) * messageLabelHeight); + } + } + + // Add some bottom margin for the notice view + noticeViewHeight += 30.0; + + // Make sure we hide completely the view, including its shadow + float hiddenYOrigin = self.slidingMode == WBNoticeViewSlidingModeDown ? -noticeViewHeight - 20.0: self.view.bounds.size.height; + + // Make and add the notice view + self.gradientView = [[WBRedGradientView alloc] initWithFrame:CGRectMake(0.0, hiddenYOrigin, viewWidth, noticeViewHeight + 10.0)]; + [self.view addSubview:self.gradientView]; + if (self.languageDirection == RightToLeft) + { + CGRect msgRect = self.messageLabel.frame ; + msgRect.origin.x = 320 - self.messageLabel.frame.size.width - 70; + self.messageLabel.frame = msgRect ; + // this if is added so that arabic message should bhave correct X + } + // Make and add the icon view + + iconView.image = [UIImage imageWithContentsOfFile:noticeIconImageName]; + iconView.contentMode = UIViewContentModeScaleAspectFit; + iconView.alpha = 0.8; + [self.gradientView addSubview:iconView]; + + // Add the title label + [self.gradientView addSubview:self.titleLabel]; + + // Add the message label + [self.gradientView addSubview:self.messageLabel]; + [self.gradientView setTag:50] ; + // Add the drop shadow to the notice view + CALayer *noticeLayer = self.gradientView.layer; + noticeLayer.shadowColor = [[UIColor blackColor]CGColor]; + noticeLayer.shadowOffset = CGSizeMake(0.0, 3); + noticeLayer.shadowOpacity = 0.50; + noticeLayer.masksToBounds = NO; + noticeLayer.shouldRasterize = YES; + + self.hiddenYOrigin = hiddenYOrigin; + + [self displayNotice]; +} + +@end diff --git a/NoticeView/WBNoticeView/MySuccessNotice.h b/NoticeView/WBNoticeView/MySuccessNotice.h new file mode 100644 index 0000000..b8088bb --- /dev/null +++ b/NoticeView/WBNoticeView/MySuccessNotice.h @@ -0,0 +1,12 @@ +// +// MySuccessNotice.h + +// +// Created by Abuzar Amin on 25/02/2015. + +#import "WBNoticeView.h" + +@interface MySuccessNotice : WBNoticeView + ++ (MySuccessNotice*)successNoticeInView:(UIView *)view title:(NSString *)title message:(NSString *)message languageDirection: (LanguageDirection) direction; +@end diff --git a/NoticeView/WBNoticeView/MySuccessNotice.m b/NoticeView/WBNoticeView/MySuccessNotice.m new file mode 100644 index 0000000..5ba6bec --- /dev/null +++ b/NoticeView/WBNoticeView/MySuccessNotice.m @@ -0,0 +1,147 @@ +// +// MySuccessNotice.m + +// +// Created by Abuzar Amin on 25/02/2015. + + +#import "MySuccessNotice.h" + +#import "WBSuccessNoticeView.h" +#import "WBNoticeView+ForSubclassEyesOnly.h" +#import "WBBlueGradientView.h" + +@implementation MySuccessNotice + ++ (MySuccessNotice*)successNoticeInView:(UIView *)view title:(NSString *) title message:(NSString *)message languageDirection: (LanguageDirection) direction +{ + MySuccessNotice *notice = [[MySuccessNotice alloc]initWithView:view title:title]; + + notice.sticky = NO; + notice.languageDirection = direction; + notice.message = message ; + return notice; +} + +- (void)show +{ + // Obtain the screen width + CGFloat viewWidth = self.view.bounds.size.width; + UIImageView *iconView ; + // Locate the images + NSString *path = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"NoticeView.bundle"]; + NSString *noticeIconImageName = [path stringByAppendingPathComponent:@"notice_success_icon.png"]; + + // Make and add the title label + float titleYOrigin = 10.0; + if (self.languageDirection == RightToLeft) + { + self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0 + (self.contentInset.left), titleYOrigin + (self.contentInset.top), viewWidth - 70.0 - (self.contentInset.right+self.contentInset.left) , 16.0)]; + self.titleLabel.textAlignment = NSTextAlignmentRight ; + + + + self.messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(15 , 20.0 + 10.0 + (self.contentInset.top), viewWidth-70, 12.0)]; + self.messageLabel.textAlignment = NSTextAlignmentRight ; + + + iconView = [[UIImageView alloc]initWithFrame:CGRectMake(290.0, 10.0, 20.0, 30.0)]; + } + else{ + self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(55.0 + (self.contentInset.left), titleYOrigin + (self.contentInset.top), viewWidth - 70.0 - (self.contentInset.right+self.contentInset.left) , 16.0)]; + self.titleLabel.textAlignment = NSTextAlignmentLeft ; + // self.titleLabel.font = [DDTheme englishCustomFontWithBold:14.0] ; + self.titleLabel.font = [UIFont boldSystemFontOfSize:14.0]; + + self.messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(55.0 + (self.contentInset.left), 20.0 + 10.0 + (self.contentInset.top), viewWidth - 70.0 - (self.contentInset.right+self.contentInset.left), 12.0)]; + self.messageLabel.textAlignment = NSTextAlignmentLeft ; + // self.messageLabel.font = [DDTheme englishCustomFont:13.0] ; + self.messageLabel.font = [UIFont systemFontOfSize:13.0]; + iconView = [[UIImageView alloc]initWithFrame:CGRectMake(10.0, 10.0, 20.0, 30.0)]; + } + + // NSLog(@"titleLabelFrame: %@", NSStringFromCGRect(self.titleLabel.frame)); + // self.titleLabel.layer.borderWidth = 1; + // self.titleLabel.layer.borderColor = [UIColor greenColor].CGColor; + self.titleLabel.textColor = [UIColor whiteColor]; + self.titleLabel.shadowOffset = CGSizeMake(0.0, -1.0); + self.titleLabel.shadowColor = [UIColor blackColor]; + //self.titleLabel.font = [UIFont boldSystemFontOfSize:14.0]; + self.titleLabel.backgroundColor = [UIColor clearColor]; + self.titleLabel.text = self.title; + + // Make the message label + //self.messageLabel.font = [UIFont systemFontOfSize:13.0]; + self.messageLabel.textColor = [UIColor whiteColor]; + self.messageLabel.backgroundColor = [UIColor clearColor]; + self.messageLabel.text = self.message; + + // Calculate the number of lines it'll take to display the text + NSInteger numberOfLines = [[self.messageLabel lines]count]; + self.messageLabel.numberOfLines = numberOfLines; + [self.messageLabel sizeToFit]; + CGFloat messageLabelHeight = self.messageLabel.frame.size.height; + + CGRect r = self.messageLabel.frame; + r.origin.y = self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height; + + float noticeViewHeight = 0.0; + double currOsVersion = [[[UIDevice currentDevice]systemVersion]doubleValue]; + if (currOsVersion >= 6.0f) { + noticeViewHeight = messageLabelHeight; + } else { + // Now we can determine the height of one line of text + r.size.height = self.messageLabel.frame.size.height * numberOfLines; + r.size.width = viewWidth - 70.0; + self.messageLabel.frame = r; + + // Calculate the notice view height + noticeViewHeight = 10.0; + if (numberOfLines > 1) { + noticeViewHeight += ((numberOfLines - 1) * messageLabelHeight); + } + } + + // Add some bottom margin for the notice view + noticeViewHeight += 30.0; + + // Make sure we hide completely the view, including its shadow + float hiddenYOrigin = self.slidingMode == WBNoticeViewSlidingModeDown ? -noticeViewHeight - 20.0: self.view.bounds.size.height; + + // Make and add the notice view + self.gradientView = [[WBBlueGradientView alloc] initWithFrame:CGRectMake(0.0, hiddenYOrigin, viewWidth, noticeViewHeight + 10.0)]; + [self.view addSubview:self.gradientView]; + if (self.languageDirection == RightToLeft) + { + CGRect msgRect = self.messageLabel.frame ; + msgRect.origin.x = 320 - self.messageLabel.frame.size.width - 70; + self.messageLabel.frame = msgRect ; + // this if is added so that arabic message should bhave correct X + } + + // Make and add the icon view + iconView.image = [UIImage imageWithContentsOfFile:noticeIconImageName]; + iconView.contentMode = UIViewContentModeScaleAspectFit; + iconView.alpha = 0.8; + [self.gradientView addSubview:iconView]; + + // Add the title label + [self.gradientView addSubview:self.titleLabel]; + + // Add the message label + [self.gradientView addSubview:self.messageLabel]; + [self.gradientView setTag:50] ; + // Add the drop shadow to the notice view + CALayer *noticeLayer = self.gradientView.layer; + noticeLayer.shadowColor = [[UIColor blackColor]CGColor]; + noticeLayer.shadowOffset = CGSizeMake(0.0, 3); + noticeLayer.shadowOpacity = 0.50; + noticeLayer.masksToBounds = NO; + noticeLayer.shouldRasterize = YES; + + self.hiddenYOrigin = hiddenYOrigin; + + [self displayNotice]; +} + +@end diff --git a/NoticeView/WBNoticeView/WBNoticeView.h b/NoticeView/WBNoticeView/WBNoticeView.h index 8537b4f..b89f0b9 100644 --- a/NoticeView/WBNoticeView/WBNoticeView.h +++ b/NoticeView/WBNoticeView/WBNoticeView.h @@ -13,6 +13,12 @@ typedef enum WBNoticeViewSlidingMode { WBNoticeViewSlidingModeDown, } WBNoticeViewSlidingMode; +typedef enum +{ + LeftToRight = 0 , + RightToLeft = 1 +}LanguageDirection; + /** `WBNoticeView` objects provides a lightweight, non-intrusive means for displaying information to the user. The `WBNoticeView` class is an abstract class that encapsulates the interface common to all notice objects. */ @@ -116,6 +122,14 @@ typedef enum WBNoticeViewSlidingMode { */ @property (nonatomic, readwrite, getter = isFloating) BOOL floating; +/** +An enum which specifices the direction of the language + + **Default**: Left to right + */ +@property (nonatomic, assign) LanguageDirection languageDirection; + + ///---------------------------------------- /// @name Showing and Dismissing the Notice ///----------------------------------------