Skip to content

Commit cf89421

Browse files
committed
Merge pull request #26 from fouquet/master
New quick presentation method for custom UIFont and NSTextAlignment
2 parents 213f5d2 + aadf032 commit cf89421

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

CSNotificationView/CSNotificationView.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ typedef enum {
3131
message:(NSString*)message
3232
duration:(NSTimeInterval)duration;
3333

34+
+ (void)showInViewController:(UIViewController*)viewController
35+
tintColor:(UIColor*)tintColor
36+
font:(UIFont*)font
37+
textAlignment:(NSTextAlignment)textAlignment
38+
image:(UIImage*)image
39+
message:(NSString*)message
40+
duration:(NSTimeInterval)duration;
41+
3442
#pragma mark + creators
3543

3644
+ (CSNotificationView*)notificationViewWithParentViewController:(UIViewController*)viewController

CSNotificationView/CSNotificationView.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,34 @@ + (void)showInViewController:(UIViewController*)viewController
5858

5959
}
6060

61+
+ (void)showInViewController:(UIViewController*)viewController
62+
tintColor:(UIColor*)tintColor
63+
font:(UIFont*)font
64+
textAlignment:(NSTextAlignment)textAlignment
65+
image:(UIImage*)image
66+
message:(NSString*)message
67+
duration:(NSTimeInterval)duration
68+
{
69+
NSAssert(message, @"'message' must not be nil.");
70+
71+
__block CSNotificationView* note = [[CSNotificationView alloc] initWithParentViewController:viewController];
72+
note.tintColor = tintColor;
73+
note.image = image;
74+
note.textLabel.font = font;
75+
note.textLabel.textAlignment = textAlignment;
76+
note.textLabel.text = message;
77+
78+
void (^completion)() = ^{[note setVisible:NO animated:YES completion:nil];};
79+
[note setVisible:YES animated:YES completion:^{
80+
double delayInSeconds = duration;
81+
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
82+
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
83+
completion();
84+
});
85+
}];
86+
87+
}
88+
6189
+ (void)showInViewController:(UIViewController *)viewController
6290
style:(CSNotificationViewStyle)style
6391
message:(NSString *)message

0 commit comments

Comments
 (0)