scalessec / toast-swift Goto Github PK
View Code? Open in Web Editor NEWA Swift extension that adds toast notifications to the UIView object class.
License: MIT License
A Swift extension that adds toast notifications to the UIView object class.
License: MIT License
that not works in swift 3.0 with cocoapods
Just upgraded the codebase to use Swift 3 and Toast-Swift has stopped working for me.
If I use
self.view.makeToast(
"Update partner information failed. Please try again.",
duration: 3.0,
position: .Center)
it complains: Ambiguous reference to member 'makeToast(_:duration:position:)'
If I use
self.view.makeToast(
message: "Update partner information failed. Please try again.",
duration: 3.0,
position: .Center)
it complains: Argument labels '(message:, duration:, position:)' do not match any available overloads
What is the right way to call makeToast()?
Thanks!
Can you add this feature, please?
First and foremost, thank you for the amazing work you're sharing with us! Really!
I have been using your framework mostly in objective-c and now that I'm obliged to work in swift I have noticed that the ToastPosition.center doesn't 'work'.
I will be doing a workaround by passing a point as position.
Kind regards.
Working on my new release I have modified my podfile to request the Swift 3 branch. After running pod install, Xcode attempts to migrate Toast.swift to use the new access control identifiers "open" and "fileprivate".
When displaying the toast in a table view controller, it always shows beneath the table headers (the toast is cut off by the table headers).
This may be confusing for others aswell, causing them opt out of the manual install.
Can you guide me towards linking the file to QuartzCore?
thanks!
I'm trying to get Toast-Swift to work and my sample calls are:
self.view.makeToastActivity(.center)
and self.view.makeToast("SUCCESS")
If I call makeToastActivity
alone, it works.
If I call them both in order, both work.
But if I call makeToast
alone, I get this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView makeToast:]: unrecognized selector sent to instance 0x7fe1b0d3e8c0'
Any insight as to why this is happening?
*** Building scheme "ToastSwiftFramework" in Toast-Swift.xcodeproj
:0: warning: argument unused during compilation: '-iapinotes-modules /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/arm64'
:0: warning: argument unused during compilation: '-iapinotes-modules /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/armv7'
Thank you for your source.
it is really good to my project.
I wonder about text messege align.
I know that text messege is left align now.
but, I want align center.
is it possible?
I'm using a Toast Activity indicator to show that results are being fetched when a user type in a search bar. Every time the search text is updated, there is another call to makeToastActivity. The documentation says that only one activity view will be created, but I wind up with dozens, and calling hideToastActivity any number of times only gets rid of the top one on the stack.
I presume this is not intended behavior, but if it is, is there a way to get a reference to the activity view so I can avoid creating duplicates?
Hi!
I just wanted to let you know that in your documentation on your github page, it says:
// create a new style
let style = ToastStyle()
// this is just one of many style options
style.messageColor = UIColor.blue
This does not compile because style is a constant.
Can you change this to
// create a new style
var style = ToastStyle()
// this is just one of many style options
style.messageColor = UIColor.blue
I know, this is a small detail, but I just wanted you to know
Thank you :)
BR
Arthur
This is the error message when building. Look at the bottom part please.
Ld /Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Products/Debug-iphonesimulator/SatePartnerIOS.app/SatePartnerIOS normal x86_64
cd /Users/felixwang/Products/Sate/SatePartnerIOS
export IPHONEOS_DEPLOYMENT_TARGET=9.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.2.sdk -L/Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Products/Debug-iphonesimulator -F/Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Products/Debug-iphonesimulator -F/Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Products/Debug-iphonesimulator/GTMSessionFetcher -F/Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Products/Debug-iphonesimulator/GoogleToolboxForMac -F/Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Products/Debug-iphonesimulator/Toast-Swift -F/Users/felixwang/Products/Sate/SatePartnerIOS/Pods/FirebaseAnalytics/Frameworks/frameworks -F/Users/felixwang/Products/Sate/SatePartnerIOS/Pods/FirebaseAuth/Frameworks/frameworks -F/Users/felixwang/Products/Sate/SatePartnerIOS/Pods/FirebaseCore/Frameworks -F/Users/felixwang/Products/Sate/SatePartnerIOS/Pods/FirebaseDatabase/Frameworks -F/Users/felixwang/Products/Sate/SatePartnerIOS/Pods/FirebaseInstanceID/Frameworks/frameworks -F/Users/felixwang/Products/Sate/SatePartnerIOS/Pods/GoogleInterchangeUtilities/Frameworks/frameworks -F/Users/felixwang/Products/Sate/SatePartnerIOS/Pods/GoogleSymbolUtilities/Frameworks/frameworks -filelist /Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Intermediates/SatePartnerIOS.build/Debug-iphonesimulator/SatePartnerIOS.build/Objects-normal/x86_64/SatePartnerIOS.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Intermediates/SatePartnerIOS.build/Debug-iphonesimulator/SatePartnerIOS.build/Objects-normal/x86_64/SatePartnerIOS_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Intermediates/SatePartnerIOS.build/Debug-iphonesimulator/SatePartnerIOS.build/Objects-normal/x86_64/SatePartnerIOS.swiftmodule -ObjC -lc++ -licucore -lsqlite3 -lz -framework AddressBook -framework CFNetwork -framework FirebaseAnalytics -framework FirebaseAuth -framework FirebaseCore -framework FirebaseDatabase -framework FirebaseInstanceID -framework GTMSessionFetcher -framework GoogleInterchangeUtilities -framework GoogleSymbolUtilities -framework GoogleToolboxForMac -framework Security -framework StoreKit -framework SystemConfiguration -framework Toast_Swift -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Intermediates/SatePartnerIOS.build/Debug-iphonesimulator/SatePartnerIOS.build/SatePartnerIOS.app.xcent -framework Pods_SatePartnerIOS -Xlinker -dependency_info -Xlinker /Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Intermediates/SatePartnerIOS.build/Debug-iphonesimulator/SatePartnerIOS.build/Objects-normal/x86_64/SatePartnerIOS_dependency_info.dat -o /Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Products/Debug-iphonesimulator/SatePartnerIOS.app/SatePartnerIOS
ld: /Users/felixwang/Library/Developer/Xcode/DerivedData/SatePartnerIOS-awzwcapidujzoagsdtwreyhzjzkp/Build/Products/Debug-iphonesimulator/Toast_Swift.framework/Toast_Swift compiled with older version of Swift language (2.0) than previous files (3.0) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
when i converted my project to latest swift
i got errors in these
func handleToastTapped(_ recognizer: UITapGestureRecognizer) {
if let toast = recognizer.view, let timer = objc_getAssociatedObject(toast, &ToastKeys.Timer) as? Timer {
timer.invalidate()
self.hideToast(toast, fromTap: true)
}
}
func toastTimerDidFinish(_ timer: Timer) {
if let toast = timer.userInfo as? UIView {
self.hideToast(toast)
}
}
timer is ambiguous for type lookup in this context
Why don't you put the queue
on the ToastManager
?
I reckon extensions don't allow stored properties for a reason, and using associated objects is going against the spirit of this.
Inside Toast.swift after setting messageNumberOfLines = 1
I had to add two lines of code to ensure an ellipsis was added if the message would exceed the maxWidthPercentage
and maxHeightPercentage
. This is because sizeThatFits()
is returning the full size required to fit all the text, not clamping it to maxMessageSize.
The fix:
let maxMessageSize = CGSize(width: (self.bounds.size.width * style.maxWidthPercentage) - imageRect.size.width, height: self.bounds.size.height * style.maxHeightPercentage)
var messageSize = messageLabel?.sizeThatFits(maxMessageSize)
if var messageSize = messageSize {
messageSize.width = min(messageSize.width, maxMessageSize.width) // Added
messageSize.height = min(messageSize.height, maxMessageSize.height) // Added
messageLabel?.frame = CGRect(x: 0.0, y: 0.0, width: messageSize.width, height: messageSize.height)
}
(XCode 7.3)
Please consider this scenario:
Can we have an option that if it should NOT show the other queued toast message IF they have same string content with the current toast displayed and in period of time.
Lets say the show duration is 2 secs. If I clicked it 5 times within 2 secs, it will only show once.
A simple toast calle with:
self.view.makeToast("msg")
Do not show if the toast is called from view on tab view controller. If the view no is inside tab controller the toast is correct.
I use toast.swift manually installed version 1.4.0 in xcode 7.2 with swift 2.2
Version 2.0.0
is missing from CocoaPods, due to issues related to CocoaPods and Xcode8. As of today, pod lib lint
fails and therefore 2.0.0 can't be published.
This is the same issue:
CocoaPods/CocoaPods#5663
And that issue has this cause:
CocoaPods/CocoaPods#5661
This should be fixed when the next version of Cocoapods is released.
Call make makeToastActivity and hideToastActivity frequently in pairs. And ToastActivity never disappear.
In func hideToastActivity, the below codes should be moved before the call of UIView.animateWithDuration.
objc_setAssociatedObject(self, &ToastKeys.ActivityView, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
Maybe It's a low-level question, but really I want to know why use the runtime, why not use computed properties?
When ToastManager.shared.queueEnabled
is true,
Plural toast view are generated.
[Now]↓
if let _ = objc_getAssociatedObject(self, &ToastKeys.ActiveToast) as? UIView where ToastManager.shared.queueEnabled {
objc_setAssociatedObject(toast, &ToastKeys.Duration, NSNumber(double: duration), .OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(toast, &ToastKeys.Position, NSValue(CGPoint: position), .OBJC_ASSOCIATION_RETAIN_NONATOMIC);
self.queue.addObject(toast)
} else {
self.showToast(toast, duration: duration, position: position)
}
[Revised edition]↓
if let _ = objc_getAssociatedObject(self, &ToastKeys.ActiveToast) as? UIView {
if ToastManager.shared.queueEnabled {
objc_setAssociatedObject(toast, &ToastKeys.Duration, NSNumber(double: duration), .OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(toast, &ToastKeys.Position, NSValue(CGPoint: position), .OBJC_ASSOCIATION_RETAIN_NONATOMIC);
self.queue.addObject(toast)
}
} else {
self.showToast(toast, duration: duration, position: position)
}
Seems that #34 still exists. When the keyboard is shown, the bottom toast is blocked.
For a login page, I want to show the toast while segue-ing to the next ViewController. How can I do this?
Thanks.
Nishant
It'd be great if you could make a certain view to show a permanent informative toast until certain condition is accomplished and the remove it.
Hello,
I want to show toast on top of screen and doing like this,
self.view.makeToast("Toast", duration: 1.0, position: ToastPosition.top)
but it is not showing toast. When I change position to center or bottom it shows toast.
I have Toast-Swift, 1.4.0
i am using autolayout. Whenever i do
self.view.makeToast("Area has been saved. You can now start tracking", duration: 2.0, position: CSToastPositionCenter)
No matter what position i set, it always set the view in either top left or top right corner?
'ToastStyle' cannot be constructed because it has no accessible initializers
Xcode 7.3
Hello, we are working on a project and needed to show a toast. We found your library and added it. The problem is that there are sometimes when we need to hide the toast manually. We would need that function to be public. What do you think?
Hello ! I've been using the framework at work, and I really like it, but I run into the issue that I needed it to hide a toast programmatically and there was no possibility for that. There is a private hide toast method; is there any particular reason why you decided to make it private, or just didn't feel the need to make it public?
The situation was that we didn't want a queue of toasts and neither toasts overlapping. I think it would be great to have a "mode" were you can choose from queue, "normal" (showing one on top of the other) and "unique" (a view can show one toast at a time). I think it could be done, for example, by storing in the view the lastToast shown (as a UIView?) and hide the lastToast before showing a new one and updating the property.
But apart from having a mode option for unique toast showing, I think having the public hideToast method can give the programmer more flexibility for the exceptional case they run into.
What do you think?
Is there a way to make a full-width toast?
当有键盘的时候会遮挡toast
Hello,
is there a way to dismiss one given toast or all toasts?
I am using toasts in a TableView. Every time I click an item to add it in my favorite items, I display a toast "item added to favorites". The problem is that when I scroll down and views are recycled, I can see the toast on another item for a short moment (depending on the duration of the toast).
Do you see a way to fix this?
Thanks!
Arnaud.
I wished to define an style for Toast in appdelegate. Can it be possible through appearance?
Seems that the only ToastPositions are .Top
, .Center
, and .Bottom
or a specific CGPoint can be used.
If one would like to position a toast in a particular area, for example in place of the status bar or over the navigation bar, how can one do so?
Installing Toast-Swift via Cocoapods results in errors.
This is the module Toast_Swift
after installing with use_frameworks!
needed for Swift
import ObjectiveC
import Toast_Swift
import Toast_Swift.Swift
import UIKit
public var Toast_SwiftVersionNumber: Double
As you can see the module references itself...
Is this a bug or am I doing something wrong?
"type metadata for (extension in myproject):__ObjC.UIView.(ToastError in _9435D8AD737309FD1AA87C6149FEA121)", referenced from:
ld: symbol(s) not found for architecture arm64
cant compile it on arm64 architecture.
I have not used Toast on Android or elsewhere. I came across your project and it seemed like an easy way to pop up status message in my app.
I have a dark section across the bottom of my App, so I want to use .Bottom but I thought I could use verticalPadding to raise the location up higher on the screen.
I am not using images or titles, just messages.
This line is causing a problem for my use case:
Swift let wrapperHeight = max((messageRect.origin.y + messageRect.size.height + style.verticalPadding), (imageRect.size.height + (style.verticalPadding * 2.0)))
Basically, if I set the padding to something like 120 to push the Toast box up, it also makes the wrapper view large, so a label with height 20 is shown on a gray background that has a large height.
Seems like a bug?
I'll fork and resolve it
As the title says, version 1 isn't found.
Podfile contains
pod 'Toast-Swift', '~> 1.0.0'
output from running pod install
is
[!] Unable to satisfy the following requirements:
Toast-Swift (~> 1.0.0)
required byPodfile
I would like the image on top only the message not side by side
There are 2 funcs have the same feature, and xCode complain it when reference one of them
func makeToastActivity(_ position: CGPoint)
func makeToastActivity(_ position: ToastPosition)
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.