gpt4 book ai didi

c# - Toast 通知 Xamarin iOS

转载 作者:可可西里 更新时间:2023-11-01 05:05:10 24 4
gpt4 key购买 nike

我正在使用 Xamarin (C#) 编写适用于 iOS 的应用程序。

iOS 中 Android 的“toast 通知”相当于什么?

来自 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, 0, 300, 100));
viewBack.BackgroundColor = UIColor.Black;
viewBack.Tag = 1989;
UILabel lblMsg = new UILabel(new CoreGraphics.CGRect(0, 20, 300, 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();
}

关于c# - Toast 通知 Xamarin iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34769242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com