scalessec / toast Goto Github PK
View Code? Open in Web Editor NEWAn Objective-C category that adds toast notifications to the UIView object class.
License: MIT License
An Objective-C category that adds toast notifications to the UIView object class.
License: MIT License
The way the code is currently written, if you show a toast, it will always be completely opaque -- the alpha is always 1.
Originally, I thought passing in the alpha value might be a good way to do it, but there are some other values that might be nice to configure (basically, many of the static const
values). It might be nice to add support to customize these values.
I thought of a few ways this could be done. The easiest might be to read from UserDefaults to see if there is a value to use instead of the hardcoded value. If not, it uses the original value.
The default toast (bottom) is hidden behind the tab bar when calling it from a TableViewController inside a NavigationController inside a TabBarController (other configurations not tested).
I 'd like you to put toast in queue and toast could show out one by one. I want to only show one toast at one time in my app but now, the toast need time to dismiss and may two toast appears and overlap . Need your help~~~~
Thanks.
Possible? Thanks.
To reproduce:
messageNumberOfLines
to 1
.makeToast:
a long message.Result:
The makeToast wrapper view is sized to the full message length, regardless of the number of lines.
To fix:
We should use sizeThatFits:
on the labels and remove the cs_sizeForString:
helper method completely.
This is also affecting titleNumberOfLines
.
Hi,
Could you please add a new api which can take a completion block, basically I need to queue the toast messages, such a api will help a lot. Thanks.
'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:
My English is not very good, the problem is: when the user interacts with the interface several times showtoash, it will always show the message will not stop, I would like to have a history of the destruction of the news, and then show the information now.
我的英语不是很好,问题是:当用户与界面交互多次 showtoash,它将始终显示消息 不会停止,我想有一个销毁历史消息,显示现在信息。
When device in Portrait Upside Down toast shown in wrong orientation
Can the project support carthage?
I've got 3 warnings when using your library and not using ARC:
Toast+UIView.m:97:49: '__bridge' casts have no effect when not using ARC
Toast+UIView.m:171:32: '__bridge' casts have no effect when not using ARC
Toast+UIView.m:178:54: '__bridge' casts have no effect when not using ARC
Hello All,
if i was validate my text field, any error are generate then i am display it on ToastView. as well as i was focus on that text field as well. so i am write down following code :
[textfield becomeFirstResponder];
[[[UIApplication sharedApplication] keyWindow] makeToast:InvalidPassword duration:3.0 position:@"bottom"];
but my toast view hide behind the keyboard. so how can i solve it. I am using Storyboard.
Displaying a toast in a view which has scrollview cannot guarantee that it would appear where you expect it to be. Using the window's frame guarantees that positions will constant.
newish to github but here are the changes I made to support tabs.
Please make the following change to support tabbed views
add to top of .m
static const int TabBarHeight = 56; //standard height of the tab bar ios 7 +
in .m change centerPointForPosition to:
(CGPoint)centerPointForPosition:(id)point withToast:(UIView *)toast {
if([point isKindOfClass:[NSString class]]) {
// convert string literals @"top", @"bottom", @"center", @"bottom_tabbed", or any point wrapped in an NSValue object into a CGPoint
if([point caseInsensitiveCompare:@"top"] == NSOrderedSame) {
return CGPointMake(self.bounds.size.width/2, (toast.frame.size.height / 2) + CSToastVerticalPadding);
} else if([point caseInsensitiveCompare:@"bottom"] == NSOrderedSame) {
return CGPointMake(self.bounds.size.width/2, (self.bounds.size.height - (toast.frame.size.height / 2)) - CSToastVerticalPadding);
} else if([point caseInsensitiveCompare:@"center"] == NSOrderedSame) {
return CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
} else if([point caseInsensitiveCompare:@"bottom_tabbed"] == NSOrderedSame){
return CGPointMake(self.bounds.size.width/2, (self.bounds.size.height - (toast.frame.size.height / 2)) - CSToastVerticalPadding -TabBarHeight);
}
} else if ([point isKindOfClass:[NSValue class]]) {
return [point CGPointValue];
}
NSLog(@"Warning: Invalid position for toast.");
return [self centerPointForPosition:CSToastDefaultPosition withToast:toast];
}
sizeWithFont is deprecated in iOS 7. boundingRectWithSize is said to be a valid substitute though I can't get it to work.
NOTICE FOR "sizeWithFont":
'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:
REPLACEMENT CODE ACCORDING TO APPLE:
// size the title label according to the length of the text
CGSize maxSizeTitle = CGSizeMake((self.bounds.size.width * CSToastMaxWidth) - imageWidth, self.bounds.size.height * CSToastMaxHeight);
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = titleLabel.lineBreakMode;
CGSize expectedSizeTitle = [title boundingRectWithSize:maxSizeTitle
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:titleLabel.font, NSParagraphStyleAttributeName:paragraphStyle.copy}
context:nil].size;
titleLabel.frame = CGRectMake(0.0, 0.0, expectedSizeTitle.width, expectedSizeTitle.height);
As seen above the replacement is not sizing correctly. If you have time, please look into this. I do not think it is very hard to fix but I do not have the time myself :(
Thanks for an otherwise great code 👍
Love it! Easy, works great, thanks!
One great thing about Toasts on Android is that they show even if your activity is finished. Can you think of a way to do that with your iPhone Toast code? If I use [self makeToast], where self is a UIViewController, the toast won't show if I immediately pop the view controller. Any ideas?
Is it possible to have the view behind the toast blur?
The UIView+Toast.h header file uses UIView
but doesn't import <UIKit/UIKit.h>
. This can lead to problems when the library source files are copied into new projects.
The file in question is a category of UIView (not a category of Toast.m as the name Toast+UIView.m would suggest).
Not a bug, just an improvement:
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(toastTimerDidFinish:) userInfo:toast repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
Hello,
Is it possible to add a cancel/dismiss button in order not to dismiss toast by timer but with button?
Thanks for your nice tool.
George Gerardis
When use [self.view makeToastActivity],
how to set the background view's alpha,not the activityView's alpha.
thank you!
For example, if using an iPad in landscape and making a toast:
[self.window makeToast:message duration:duration position:position];
The toast will always be at the physical bottom of the device (i.e. above the home button), regardless of the position parameter.
As mention in #53, if the title or message is shorter than the width of the wrapper view, it does not appear to be centered.
Toast/Toast/Toast/Toast+UIView.m:237:20: 'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:
maybe fix it
I am updating UIView+toast, but my project heavily uses disappearToast. Latest code does not have it. What happened? What can I use now?
Right now fade-in and fade-out duration is fixed. it will be nice to be able to configure it as well.
Add please customize background, more options, thanks
I want some toasts in my app to respond to user taps and some to ignore user taps. Currently, the CSToastHidesOnTap
is a global static const
, so I don't think I can set it on a toast-by-toast basis, can I? I think I'll have to turn this into a UIView
subclass and add a @property hidesOnTap
.
I'm just checking that there isn't some use of the static const
that I'm missing before I stray from the UIView
category paradigm.
I'm a new baby to IOS dev,I don't know how to use it in swift project.
is like this?
import UIView+Toast
If I switch to another screen with visible toast, exc_bad_access happens in animationDidStop. On line UIView *toast = (UIView *)(__bridge id)context;
For now, the only way to toast is to call it from a specific view.
[someView makeToast:@"oops"];
But what if we don't care about the view, what if we just want to display a toast right away regardless of where we are. Like:
[Toast makeToast:@"oops"];
What do you think about this? Are we going to implement it in the future?
The Toast view doesn't appear to work well when the device orientation is changed. If the Toast view is centered for example and while it's being displayed, the device is rotated, the Toast view doesn't remain centered.
I'd like to disable duration, so this toast message bar is show always.
Is there any option for this?
Would be great to have a ARC ready version
It works like a charm when I compile it with SDK 7
But when I try to do it with the 6.1 I get the following error on UIView+Toast.m
CGRect boundingRect = [string boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
ERROR : No visible @interface for 'NSString' declares the selector 'boundingRectWithSize:options:attributes:context:'
Does it work with SDK 6.1? or just with 7?
Finallly , just to give more details, I have installed manually so I have copied the .m and .h and I have made sure that the Quartzcore.framework is added.
I have downloaded this popup and love it. What I don't like is that it auto hides it after 3 secs. Is there a way I can enable touch gesture so that when a user touches the popup it hides it only then?
I have been banging my head left and right and can't figure out. I tried this and this doesn't work.
(void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position title:(NSString *)title {
NSLog(@"inside here ...");
UIView *toast = [self viewForMessage:message title:title image:nil];
UIGestureRecognizer *gesture;
gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:toast:)];
[self addGestureRecognizer:gesture];
[self showToast:toast duration:interval position:position];
}
(void)handleTap:(UIView *)toast:(UIPanGestureRecognizer *)gesture
{
NSLog(@"handleTap ....");
[toast removeFromSuperview];
}
It would be good to have a onCompleted block or similar, to know when the toast has been removed from the screen. Or at least some way of checking to see if the toast is still on screen to avoid overlap.
Hi! Seeing EXC_BAD_ACCESS for all ios 7 devices when [[CSToastStyle alloc] initWithDefaultStyle]
is called. Thousands of crashes (can provide crashlytics but reports if it helps).
Any ideas?
- (void)makeToast:(NSString *)message
can't show toast.
I have tried
[self.view makeToast:@"This is a piece of toast with a title."
duration:3.0
position:@"top"
title:@"Toast Title"];
it works.
but
[self.view makeToast:"Toast Title"];
it doesn't work
When back to last ViewContoller , a toast view will still be shown in duration. So need hide or remove toast maked before .
when i use toast by cocoapods
it not set 's.requires_arc = true'
cause compile warning
can u help fix this problem?
when I use "UITextField" keyboard show, the toast was covered by "keyboard"!
My test code as follows:
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"test Toast";
self.view.backgroundColor = [UIColor whiteColor];
tt = [[UITextField alloc] init];
tt.frame = CGRectMake(50, 100, 200, 40);
tt.placeholder = @"UItoasttestWork";
// tt.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:tt];
UIButton *toastBtn = [[UIButton alloc] init];
toastBtn.frame =CGRectMake(255, 100, 60, 40);
[toastBtn setTitle:@"Toast" forState:UIControlStateNormal];
[toastBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[toastBtn addTarget:self action:@selector(zButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:toastBtn];
UITapGestureRecognizer *tapGeser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHidden:)];
[self.view addGestureRecognizer:tapGeser];
}
-(void)zButtonClick:(UIButton *)btn{
[self.navigationController.view makeToast:@"This is a piece of toast"];
}
Any help will be appreciated!
I use the toast in a scrollview,like:[scrollView makeToas:@""];,
If the scrollView's contentSize is very large,maybe double size of screen, so if I scroll down to bottom and make toast, the toast will show outside the visible area.
Is there a way to locate the toast at a certain position on screen?
Hello,
When we show a toast at position TOP under IOS 7,
The toast is partially hidden by navigation bar.
Is there a way to fix this behavior ?
Thanks
There should be provision to cancel toast messages.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.