cruffenach / CRToast

A modern iOS toast view that can fit your notification needs
MIT License
4.17k stars 463 forks source link

not an issue, but a swift example #205

Open AndreiD opened 8 years ago

AndreiD commented 8 years ago

Here's an example using swift. Maybe add it in the readme somewhere, because digging though stackoverflow is not nice.

import CRToast

//somewhere....
        var options:[NSObject:AnyObject]  = [
                kCRToastTextKey : "Hello World! This is a sample message up after loading the view",
                kCRToastBackgroundColorKey : UIColor.blackColor(),
                kCRToastTextColorKey: UIColor.yellowColor(),
                kCRToastTextMaxNumberOfLinesKey: 2,
                kCRToastTimeIntervalKey: 3,
                kCRToastUnderStatusBarKey : NSNumber(bool: false),
                kCRToastTextAlignmentKey : NSTextAlignment.Left.rawValue,
                //options[kCRToastImageKey] = UIImage(named: "ic_whatever") as AnyObject?
                kCRToastNotificationTypeKey : CRToastType.NavigationBar.rawValue,
                kCRToastAnimationInTypeKey : CRToastAnimationType.Gravity.rawValue,
                kCRToastAnimationOutTypeKey : CRToastAnimationType.Gravity.rawValue,
                kCRToastAnimationInDirectionKey : CRToastAnimationDirection.Top.rawValue,
                kCRToastAnimationOutDirectionKey : CRToastAnimationDirection.Top.rawValue
        ]

        CRToastManager.showNotificationWithOptions(options, completionBlock: { () -> Void in
            print("done!")
        })
nadimalam commented 7 years ago

thanks but its giving errors in swift 3

ryanjunp commented 7 years ago

let options: [String: Any] = [kCRToastTextKey: "Member joined: (member.identity)", kCRToastTextAlignmentKey: NSTextAlignment.center, kCRToastBackgroundColorKey: UIColor.red, kCRToastAnimationInTypeKey: CRToastAnimationType.gravity, kCRToastAnimationOutTypeKey: CRToastAnimationType.gravity, kCRToastAnimationInDirectionKey: CRToastAnimationDirection.left, kCRToastAnimationOutDirectionKey: CRToastAnimationDirection.right]

    CRToastManager.showNotification(options: options) {
        print("completed")
    }

This one is working example.

CocoaDebug commented 6 years ago

good