Skip to content

Add a method to change the message text #53

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

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
4 changes: 4 additions & 0 deletions CSNotificationView/CSNotificationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ typedef void(^CSVoidBlock)();
- (void)dismissWithStyle:(CSNotificationViewStyle)style message:(NSString*)message duration:(NSTimeInterval)duration animated:(BOOL)animated;
@property (readonly, nonatomic, getter = isShowing) BOOL visible;

#pragma mark - updates

- (void)updateMessage:(NSString *)message;

#pragma mark - visible properties

/**
Expand Down
8 changes: 8 additions & 0 deletions CSNotificationView/CSNotificationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ - (void)dismissWithStyle:(CSNotificationViewStyle)style message:(NSString *)mess
}];
}

#pragma mark - updates

- (void)updateMessage:(NSString *)message
{
self.textLabel.text = message;
}


#pragma mark - frame calculation

//Workaround as there is a bug: sometimes, when accessing topLayoutGuide, it will render contentSize of UITableViewControllers to be {0, 0}
Expand Down
17 changes: 15 additions & 2 deletions Example/CSNotificationViewDemo/CSRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ - (IBAction)showPermanent:(id)sender
self.permanentNotification =
[CSNotificationView notificationViewWithParentViewController:self.navigationController
tintColor:[UIColor colorWithRed:0.000 green:0.6 blue:1.000 alpha:1]
image:nil message:@"I am running for two seconds."];
image:nil message:@"I am running for five seconds."];

[self.permanentNotification setShowingActivity:YES];

Expand All @@ -89,8 +89,14 @@ - (IBAction)showPermanent:(id)sender
style:UIBarButtonItemStyleDone
target:weakself
action:@selector(cancel)];

weakself.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Update"
style:UIBarButtonItemStyleDone
target:weakself
action:@selector(update)];

double delayInSeconds = 2.0;
double delayInSeconds = 5.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[weakself success];
Expand All @@ -99,8 +105,14 @@ - (IBAction)showPermanent:(id)sender
}];
}

- (void)update
{
[self.permanentNotification updateMessage:@"This is a new message..."];
}

- (void)cancel
{
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = nil;
[self.permanentNotification dismissWithStyle:CSNotificationViewStyleError
message:@"Cancelled"
Expand All @@ -111,6 +123,7 @@ - (void)cancel

- (void)success
{
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = nil;
[self.permanentNotification dismissWithStyle:CSNotificationViewStyleSuccess
message:@"Sucess!"
Expand Down