예제 #1
0
 private void SetFont(RoundedEntry element)
 {
     //var fontService = Resolver.Get<IFontService>();
     //if (fontService == null) return;
     //if (element.IsSingleLine)
     //    textField.Font = UIFont.FromName(fontService.GetFontName(element.FontStyle), (nfloat)element.FontSize);
     //else
     //textView.Font = UIFont.FromName(fontService.GetFontName(element.FontStyle), (nfloat)element.FontSize);
     if (element.IsSingleLine)
     {
         if (textField.Font == null ||
             textField.Font.PointSize != (nfloat)element.FontSize)
         {
             textField.Font = UIFont.FromName(textField.Font.FamilyName, (nfloat)element.FontSize);
         }
     }
     else
     {
         if (textView.Font == null ||
             textView.Font.PointSize != (nfloat)element.FontSize)
         {
             textView.Font = UIFont.FromName(textView.Font.FamilyName, (nfloat)element.FontSize);
         }
     }
 }
예제 #2
0
 private void SetCornerRadius(RoundedEntry element)
 {
     if (element.CornerRadius > 0)
     {
         if (element.IsSingleLine)
         {
             textField.ClipsToBounds      = true;
             textField.Layer.CornerRadius = (nfloat)element.CornerRadius;
         }
         else
         {
             textView.ClipsToBounds      = true;
             textView.Layer.CornerRadius = (nfloat)element.CornerRadius;
         }
     }
 }
예제 #3
0
 private void SetBorder(RoundedEntry element)
 {
     if (element.BorderColor != Xamarin.Forms.Color.Default)
     {
         if (element.IsSingleLine)
         {
             textField.Layer.BorderColor = element.BorderColor.ToUIColor().CGColor;
             textField.Layer.BorderWidth = 1f;
         }
         else
         {
             textView.Layer.BorderColor = element.BorderColor.ToUIColor().CGColor;
             textView.Layer.BorderWidth = 1f;
         }
     }
 }
예제 #4
0
        private void SetTextAlignment(RoundedEntry element)
        {
            if (element.IsSingleLine)
            {
                switch (element.HorizontalTextAlignment)
                {
                case Xamarin.Forms.TextAlignment.Center:
                    textField.TextAlignment = UITextAlignment.Center;
                    break;

                case Xamarin.Forms.TextAlignment.End:
                    textField.TextAlignment = UITextAlignment.Right;
                    break;

                case Xamarin.Forms.TextAlignment.Start:
                    textField.TextAlignment = UITextAlignment.Left;
                    break;
                }
            }
            else
            {
                switch (element.HorizontalTextAlignment)
                {
                case Xamarin.Forms.TextAlignment.Center:
                    textView.TextAlignment = UITextAlignment.Center;
                    break;

                case Xamarin.Forms.TextAlignment.End:
                    textView.TextAlignment = UITextAlignment.Right;
                    break;

                case Xamarin.Forms.TextAlignment.Start:
                    textView.TextAlignment = UITextAlignment.Left;
                    break;
                }
            }
        }
예제 #5
0
        private void SetTextInputTypes(RoundedEntry element)
        {
            if (element.IsSingleLine)
            {
                switch (element.TextInputType)
                {
                case TextInputType.Normal:
                    textField.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    textField.KeyboardType           = UIKeyboardType.Default;
                    break;

                case TextInputType.EmailAddress:
                    textField.AutocapitalizationType = UITextAutocapitalizationType.None;
                    textField.KeyboardType           = UIKeyboardType.EmailAddress;
                    textField.AutocapitalizationType = UITextAutocapitalizationType.None;
                    break;

                case TextInputType.Password:
                    textField.AutocapitalizationType = UITextAutocapitalizationType.None;
                    textField.KeyboardType           = UIKeyboardType.Default;
                    break;

                case TextInputType.Phone:
                    textField.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    textField.KeyboardType           = UIKeyboardType.PhonePad;
                    break;

                case TextInputType.Number:
                    textField.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    textField.KeyboardType           = UIKeyboardType.NumberPad;
                    break;

                case TextInputType.PersonName:
                    textField.AutocapitalizationType = UITextAutocapitalizationType.Words;
                    textField.KeyboardType           = UIKeyboardType.Default;
                    break;

                case TextInputType.None:
                    textField.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    //textField.AutocapitalizationType = UITextAutocapitalizationType.None;
                    break;
                }
                textField.AutocorrectionType = UITextAutocorrectionType.No;
                textField.SpellCheckingType  = UITextSpellCheckingType.No;
            }
            else
            {
                switch (element.TextInputType)
                {
                case TextInputType.Normal:
                    textView.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    textView.KeyboardType           = UIKeyboardType.Default;
                    break;

                case TextInputType.EmailAddress:
                    textView.AutocapitalizationType = UITextAutocapitalizationType.None;
                    textView.KeyboardType           = UIKeyboardType.EmailAddress;
                    break;

                case TextInputType.Password:
                    textView.AutocapitalizationType = UITextAutocapitalizationType.None;
                    textView.KeyboardType           = UIKeyboardType.Default;
                    break;

                case TextInputType.Phone:
                    textView.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    textView.KeyboardType           = UIKeyboardType.PhonePad;
                    break;

                case TextInputType.Number:
                    textView.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    textView.KeyboardType           = UIKeyboardType.NumberPad;
                    break;

                case TextInputType.PersonName:
                    textView.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    textView.KeyboardType           = UIKeyboardType.Default;
                    break;

                case TextInputType.None:
                    textView.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                    //textField.AutocapitalizationType = UITextAutocapitalizationType.None;
                    break;
                }

                textView.AutocorrectionType = UITextAutocorrectionType.No;
                textView.SpellCheckingType  = UITextSpellCheckingType.No;
            }
        }
예제 #6
0
        private void SetText(RoundedEntry element)
        {
            if (textField != null)
            {
                if (!string.IsNullOrWhiteSpace(element.Placeholder))
                {
                    textField.AttributedPlaceholder = new Foundation.NSAttributedString(
                        element.Placeholder, foregroundColor: element.PlaceholderColor.ToUIColor());
                }
                textField.TextColor = element.TextColor.ToUIColor();

                if ((textField.Text + "").Trim() == (element.Text + "").Trim())
                {
                    return;
                }

                textField.Text = element.Text;
            }
            else
            {
                if ((textView.Text + "").Trim().Length > 0 && (textView.Text + "").Trim() == (element.Text + "").Trim())
                {
                    return;
                }

                textView.Text      = element.Text;
                textView.TextColor = element.TextColor.ToUIColor();

                if (!isBeginEditingSet)
                {
                    textView.ShouldBeginEditing = ((tv) =>
                    {
                        if (element.IsReadOnly)
                        {
                            return(false);
                        }

                        if (textView.Tag == 0)
                        {
                            textView.Text = string.Empty;
                            textView.TextColor = element.TextColor.ToUIColor();
                            textView.Tag = 1;
                            textView.SelectedRange = new NSRange(0, 0);
                        }
                        return(true);
                    });

                    textView.ShouldEndEditing = ((tv) =>
                    {
                        if (textView.Text.Length == 0)
                        {
                            textView.Text = element.Placeholder;
                            textView.TextColor = element.PlaceholderColor.ToUIColor();
                            textView.Tag = 0;
                        }
                        return(element.ShouldEndEditing);
                    });
                }

                if (textView.Text.Length == 0)
                {
                    textView.Text      = element.Placeholder;
                    textView.TextColor = element.PlaceholderColor.ToUIColor();
                    textView.Tag       = 0;

                    textView.SelectedRange = new NSRange(0, 0);
                }
            }
        }
예제 #7
0
        private void SetReturnKeyType(RoundedEntry element)
        {
            if (element.IsSingleLine)
            {
                if (element.ReturnKeyType == ReturnKeyType.Automatic)
                {
                    if (element.NextElement != null)
                    {
                        textField.ReturnKeyType = UIReturnKeyType.Next;
                    }
                    else if (element.Command != null)
                    {
                        textField.ReturnKeyType = UIReturnKeyType.Done;
                    }
                }
                else if (element.ReturnKeyType == ReturnKeyType.Default)
                {
                    textField.ReturnKeyType = UIReturnKeyType.Default;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Go)
                {
                    textField.ReturnKeyType = UIReturnKeyType.Go;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Search)
                {
                    textField.ReturnKeyType = UIReturnKeyType.Search;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Next)
                {
                    textField.ReturnKeyType = UIReturnKeyType.Next;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Done)
                {
                    textField.ReturnKeyType = UIReturnKeyType.Done;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Search)
                {
                    textField.ReturnKeyType = UIReturnKeyType.Search;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Send)
                {
                    textField.ReturnKeyType = UIReturnKeyType.Send;
                }

                if (this.textField.InputAccessoryView != null)
                {
                    this.textField.InputAccessoryView.BackgroundColor = element.InputAccessoryBackgroundColor.ToUIColor();
                }
            }
            else
            {
                if (element.ReturnKeyType == ReturnKeyType.Automatic)
                {
                    if (element.NextElement != null)
                    {
                        textView.ReturnKeyType = UIReturnKeyType.Next;
                    }
                    else if (element.Command != null)
                    {
                        textView.ReturnKeyType = UIReturnKeyType.Done;
                    }
                }
                else if (element.ReturnKeyType == ReturnKeyType.Default)
                {
                    textView.ReturnKeyType = UIReturnKeyType.Default;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Go)
                {
                    textView.ReturnKeyType = UIReturnKeyType.Go;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Search)
                {
                    textView.ReturnKeyType = UIReturnKeyType.Search;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Next)
                {
                    textView.ReturnKeyType = UIReturnKeyType.Next;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Done)
                {
                    textView.ReturnKeyType = UIReturnKeyType.Done;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Search)
                {
                    textView.ReturnKeyType = UIReturnKeyType.Search;
                }
                else if (element.ReturnKeyType == ReturnKeyType.Send)
                {
                    textView.ReturnKeyType = UIReturnKeyType.Send;
                }

                if (this.textView.InputAccessoryView != null)
                {
                    this.textView.InputAccessoryView.BackgroundColor = element.InputAccessoryBackgroundColor.ToUIColor();
                }
            }
        }