加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Toast通知Xamarin iOS

发布时间:2020-12-15 23:30:25 所属栏目:百科 来源:网络整理
导读:我正在为Xamarin(C#)编写iOS应用程序. 在iOS中,Android的“Toast notifications”相当于什么? 从documentation开始: A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message
我正在为Xamarin(C#)编写iOS应用程序.

在iOS中,Android的“Toast notifications”相当于什么?

从documentation开始:

A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive. For example,navigating away from an email before you send it triggers a “Draft saved” toast to let you know that you can continue editing later. Toasts automatically disappear after a timeout.

例如在Android(C#)中,我可以像这样显示它们:

Toast.MakeText(this,"Added " + counttext.Text +" pcs to cart",ToastLength.Long).Show();

我如何为iOS编写相同的内容?

谢谢你的回答.

解决方法

在Xamarin iOS中,您必须使用自定义设计的UIView和动画来实现相同的效果

public void ShowToast(String message,UIView view)
    {
        UIView residualView = view.ViewWithTag(1989);
        if (residualView != null)
            residualView.RemoveFromSuperview();

        var viewBack = new UIView(new CoreGraphics.CGRect(83,300,100));
        viewBack.BackgroundColor = UIColor.Black;
        viewBack.Tag = 1989;
        UILabel lblMsg = new UILabel(new CoreGraphics.CGRect(0,20,60));
        lblMsg.Lines = 2;
        lblMsg.Text = message;
        lblMsg.TextColor = UIColor.White;
        lblMsg.TextAlignment = UITextAlignment.Center;
        viewBack.Center = view.Center;
        viewBack.AddSubview(lblMsg);
        view.AddSubview(viewBack);
        roundtheCorner(viewBack);
        UIView.BeginAnimations("Toast");
        UIView.SetAnimationDuration(3.0f);
        viewBack.Alpha = 0.0f;
        UIView.CommitAnimations();
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读