Esempio n. 1
0
        public void ShowToastMessage(string message, string backgroundHexColor = null, string textHexColor = null)
        {
            _alertDelay = NSTimer.CreateScheduledTimer(ShortDelay, (obj) =>
            {
                DismissMessage();
            });

            _alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
            var tView = _alert.View;

            if (!string.IsNullOrEmpty(backgroundHexColor))
            {
                var firstSubView     = tView.Subviews?.FirstOrDefault();
                var alertContentView = firstSubView?.Subviews?.FirstOrDefault();
                if (alertContentView != null)
                {
                    foreach (UIView uiView in alertContentView.Subviews)
                    {
                        uiView.BackgroundColor = UIColor.Clear.FromHexString(backgroundHexColor);
                    }
                }
            }
            var attributedString = new NSAttributedString(message, foregroundColor: UIColor.Clear.FromHexString(textHexColor ?? "#000000"));

            _alert.SetValueForKey(attributedString, new NSString("attributedMessage"));
            IosHelper.GetVisibleViewController().PresentViewController(_alert, true, null);
        }
Esempio n. 2
0
        /// <summary>
        /// Create Toast
        /// </summary>
        /// <param name="message"></param>
        /// <param name="backgroundHexColor"></param>
        /// <param name="textHexColor"></param>
        /// <param name="toastLength"></param>
        private void CreateToast(string message, string backgroundHexColor = null, string textHexColor = null, Plugin.Toast.Abstractions.ToastLength toastLength = ToastLength.Short)
        {
            var delay = toastLength == ToastLength.Short ? ShortDelay : LongDelay;

            var alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);

            var alertDelay = NSTimer.CreateScheduledTimer(delay, (obj) =>
            {
                DismissMessage(alert, obj, null);
            });

            _lastAlert      = alert;
            _lastAlertDelay = alertDelay;

            var tView = alert.View;

            if (!string.IsNullOrEmpty(backgroundHexColor))
            {
                var firstSubView     = tView.Subviews?.FirstOrDefault();
                var alertContentView = firstSubView?.Subviews?.FirstOrDefault();
                if (alertContentView != null)
                {
                    foreach (UIView uiView in alertContentView.Subviews)
                    {
                        uiView.BackgroundColor = UIColor.Clear.FromHexString(backgroundHexColor);
                    }
                }
            }
            var attributedString = new NSAttributedString(message, foregroundColor: UIColor.Clear.FromHexString(textHexColor ?? "#000000"));

            alert.SetValueForKey(attributedString, new NSString("attributedMessage"));
            IosHelper.GetVisibleViewController().PresentViewController(alert, true, null);
        }