Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Right to left languages #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions NoticeView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
250628781651F7DC00D3443E /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 250628771651F7DB00D3443E /* [email protected] */; };
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 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 592BDDE215645BEE00B78820 /* [email protected] */; };
592BDDEB15645BEE00B78820 /* NoticeView.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 592BDDE415645BEE00B78820 /* NoticeView.bundle */; };
Expand Down Expand Up @@ -39,6 +41,10 @@
250628771651F7DB00D3443E /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "../../[email protected]"; sourceTree = "<group>"; };
3EA90DC417086FF70045E620 /* WBScrollViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WBScrollViewController.h; sourceTree = "<group>"; };
3EA90DC517086FF70045E620 /* WBScrollViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WBScrollViewController.m; sourceTree = "<group>"; };
47DC24E51AFD03200039192A /* MyErrorNoticeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyErrorNoticeView.h; sourceTree = "<group>"; };
47DC24E61AFD03200039192A /* MyErrorNoticeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyErrorNoticeView.m; sourceTree = "<group>"; };
47DC24E71AFD03200039192A /* MySuccessNotice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MySuccessNotice.h; sourceTree = "<group>"; };
47DC24E81AFD03200039192A /* MySuccessNotice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MySuccessNotice.m; sourceTree = "<group>"; };
592BDDE115645BEE00B78820 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
592BDDE215645BEE00B78820 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
592BDDE415645BEE00B78820 /* NoticeView.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = NoticeView.bundle; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
);
Expand Down
16 changes: 16 additions & 0 deletions NoticeView/WBNoticeView/MyErrorNoticeView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// MyErrorNoticeView.h
//
//
// Created by Abuzar Amin on 12/03/2015.


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


@interface MyErrorNoticeView : WBNoticeView

+ (MyErrorNoticeView *)errorNoticeInView:(UIView *)view title:(NSString *)title message:(NSString *)message languageDirection: (LanguageDirection) direction;

@end
143 changes: 143 additions & 0 deletions NoticeView/WBNoticeView/MyErrorNoticeView.m
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions NoticeView/WBNoticeView/MySuccessNotice.h
Original file line number Diff line number Diff line change
@@ -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
147 changes: 147 additions & 0 deletions NoticeView/WBNoticeView/MySuccessNotice.m
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions NoticeView/WBNoticeView/WBNoticeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
///----------------------------------------
Expand Down