Search code examples
iostoast

What is the android.widget.Toast equivalent for iOS applications?


I have made Android application a few months ago. The Toast class is very useful for me. I do not need to consider the main Thread and place to show it. Anywhere I can show it and just leave that and it is automatically disappeared.

Toast.makeToast(context, msg, Toast.LENGTH_SHORT).show();

That's it. ^^

What about iPhone? Is there something like the Toast? Just show message and do not need to care about it. It will be automatically disappeared.


Solution

  • There is no class "out-of-the-box" in UIKit to do this. But it is quite easy to create a class that will offer this behavior.

    You just have to create a class that inherit from UIView. This class will have the responsibility - to create what you want to display, - to add itself in parent view hierarchy - to dismiss itself using a timer.

    You will be able to use it like :

    [ToastView toastViewInView:myParentView withText:@"what a wonderful text"];
    

    Regards, Quentin