TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | Custom |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
This page tells you what toast notifications are and why you may need them in your iPhone/iPad application.
If you develop already for Android, then you know what it is so you can skip to the next section.
For the others of us: a toast is a spécial way to display 'non intrusive' message to the user. Those message are displayed on a configurable place on the screen and they disapear after a configurable time interval. The way they appear is similar to the way the Growl app (on mac do).
Some benefits are:
There is only one way to create an iToast: so you won't need to retain much. In it basic form, you create an iToast this way:
[[iToast makeText:NSLocalizedString(@"The activity has been successfully saved.", @"")] show];
Like in jQuery, you can chain call and terminate by using the show method, there are many things you can configure. Look bellow.
[[[iToast makeText:NSLocalizedString(@"The activity has been successfully saved.", @"")]
setGravity:iToastGravityBottom] show];
Note : Above the gravity can be any of iToastGravityBottom
, iToastGravityTop
, iToastGravityCenter
.
Or
[[[[iToast makeText:NSLocalizedString(@"Something to display a very long time", @"")]
setGravity:iToastGravityBottom] setDuration:iToastDurationLong] show];
Note : Above the duration can be any integer (the number of millisecond to display it). There is Three preset you can use for duration:
@interface iToast : NSObject {
iToastSettings *_settings;
NSInteger offsetLeft;
NSInteger offsetTop;
NSTimer *timer;
UIView *view;
NSString *text;
}
- (void) show;
- (iToast *) setDuration:(NSInteger ) duration;
- (iToast *) setGravity:(iToastGravity) gravity
offsetLeft:(NSInteger) left
offsetTop:(NSInteger) top;
- (iToast *) setGravity:(iToastGravity) gravity;
- (iToast *) setPostion:(CGPoint) position;
+ (iToast *) makeText:(NSString *) text;
-(iToastSettings *) theSettings;
@end
You don't need to set all the settings each time you want to show an iToast. There is a shared settings repo that each iToast copy it setting when first created.
To modify the shared setting, you first obtain the shared settings like:
iToastSettings *theSettings = [iToastSettings getSharedSettings];
Then you change the settings:
theSettings.duration = 4000;
@interface iToastSettings : NSObject<NSCopying>{
NSInteger duration;
iToastGravity gravity;
CGPoint postition;
iToastType toastType;
NSDictionary *images;
BOOL positionIsSet;
}
@property(assign) NSInteger duration;
@property(assign) iToastGravity gravity;
@property(assign) CGPoint postition;
@property(readonly) NSDictionary *images;
- (void) setImage:(UIImage *)img forType:(iToastType) type;
+ (iToastSettings *) getSharedSettings;
@end
You are interested by those features? write the code and share with the community.