gpt4 book ai didi

xamarin.ios - 在 UIAlertView (iOS, Xamarin) 上添加 UITextView 而不使用任何第三方库

转载 作者:行者123 更新时间:2023-12-04 14:33:16 24 4
gpt4 key购买 nike

我想在 iOS 中显示一个对话框并添加一个 UITextView到对话框的 View 。 UITextView textView 包含带有电子邮件、电话和网址的可点击链接的文本。我能够触发对话框,但只能使用标题和一个确定按钮。没有将 textview 添加到对话框 View 中。我不确定这里的问题是与 textview 还是与将 View 添加到对话框的方式有关。

请在下面检查我的代码:

 UITextView textView = new UITextView();
textView.Editable = false;
textView.DataDetectorTypes = UIDataDetectorType.All;
textView.Message = message;
var dlg = UIAlertController.Create(Title ?? String.Empty, null, UIAlertControllerStyle.Alert);
dlg.View.AddSubview(textView);
dlg.AddAction(UIAlertAction.Create(OkText, UIAlertActionStyle.Default, action => Submit()));

var top = Utils.GetTopViewController();
top.PresentViewController(dlg, animated: true, completionHandler: null);

谢谢,

最佳答案

似乎你需要一个自定义的弹出 View 来完成你所需要的,我为你写了一个示例,这是代码:

这是 ViewController.cs:

public partial class ViewController : UIViewController
{
public ViewController (IntPtr handle) : base (handle)
{
}

public override void ViewDidLoad ()
{
this.View.BackgroundColor = UIColor.Gray;
this.View.AddGestureRecognizer (new UITapGestureRecognizer (() => {
CustomPopUpView cpuv = new CustomPopUpView (new CoreGraphics.CGSize (300, 200));
cpuv.PopUp (true,delegate{
Console.WriteLine("cpuv will close");
});
}));
}
}

这是 CustomPopUpView.cs:
public class CustomPopUpView : UIView
{
public delegate void PopWillCloseHandler ();
public event PopWillCloseHandler PopWillClose;

private UIVisualEffectView effectView = new UIVisualEffectView (UIBlurEffect.FromStyle (UIBlurEffectStyle.Dark));
private UIButton btnClose = new UIButton (UIButtonType.System);

public CustomPopUpView (CGSize size)
{
nfloat lx = (UIScreen.MainScreen.Bounds.Width - size.Width) / 2;
nfloat ly = (UIScreen.MainScreen.Bounds.Height - size.Height) / 2;
this.Frame = new CGRect (new CGPoint (lx, ly), size);

effectView.Alpha = 0;

this.BackgroundColor = UIColor.White;

nfloat btnHeight = 40;
btnClose.SetTitle ("Close", UIControlState.Normal);
btnClose.Frame = new CGRect (0, this.Frame.Height - btnHeight, this.Frame.Width, btnHeight);
btnClose.TouchUpInside += delegate {
Close();
};
this.AddSubview (btnClose);
}

public void PopUp (bool animated = true, Action popAnimationFinish = null)
{
UIWindow window = UIApplication.SharedApplication.KeyWindow;
effectView.Frame = window.Bounds;
window.EndEditing (true);
window.AddSubview (effectView);
window.AddSubview (this);

if (animated) {
Transform = CGAffineTransform.MakeScale (0.1f, 0.1f);
UIView.Animate (0.15, delegate {
Transform = CGAffineTransform.MakeScale (1, 1);
effectView.Alpha = 0.8f;
},delegate {
if(null != popAnimationFinish)
popAnimationFinish ();
});
} else {
effectView.Alpha = 0.8f;
}
}

public void Close (bool animated = true)
{
if (animated) {
UIView.Animate (0.15, delegate {
Transform = CGAffineTransform.MakeScale (0.1f, 0.1f);
effectView.Alpha = 0;
}, delegate {
this.RemoveFromSuperview();
effectView.RemoveFromSuperview();
if(null != PopWillClose) PopWillClose ();
});
} else {
if(null != PopWillClose) PopWillClose ();
}
}
}

您可以向此 CustomPopUpView 添加任何您想要的内容,或者您​​可以继承它并创建您自己的弹出窗口。

希望它可以帮助你。

关于xamarin.ios - 在 UIAlertView (iOS, Xamarin) 上添加 UITextView 而不使用任何第三方库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39132860/

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