How to set top entry filling in Xamarin Forms

In my Xamarin forms application, I need to install the top add-on for the Entry control in iOS. I created renders for Entry, but only I can set Left and Right padding. Please help me. Below is my input rendering

public class CustomRenderer: EntryRenderer { protected override void OnElementChanged (ElementChangedEventArgs<Entry> e) { base.OnElementChanged (e); if (Control != null) { Control.LeftView = new UIView (new CGRect (0, 0, 15, 0)); Control.LeftViewMode = UITextFieldViewMode.Always; } } } 
+8
c # xamarin xamarin.forms
source share
2 answers

To do this, we need to do two things:

  • Increase Entry Height in Xamarin.Forms
  • Create an iOS custom renderer to align text at the bottom of a UITextField enter image description here

Increase Login Height in Xamarin.Forms

In this example, I use RelativeLayout to set the height of the filled record to 50, Constraint.Constant(50) .

 using System; using Xamarin.Forms; namespace CustomEntrySample { public class EntryWithTopPadding : Entry { } public class App : Application { public App() { var normalEntry = new Entry { Text = "This Entry Has Normal Padding", BackgroundColor = Color.Lime }; var paddedEntry = new EntryWithTopPadding { Text = "This Entry Has Extra Top Padding", BackgroundColor = Color.Aqua }; var mainLayout = new RelativeLayout(); mainLayout.Children.Add( normalEntry, Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Y + 10), Constraint.RelativeToParent(parent => parent.Width) ); mainLayout.Children.Add( paddedEntry, Constraint.Constant(0), Constraint.RelativeToView(normalEntry, (parent, view) => view.Y + view.Height + 10), Constraint.RelativeToParent(parent => parent.Width), Constraint.Constant(50) ); MainPage = new NavigationPage( new ContentPage { Title = "Title", Content = mainLayout, Padding = new Thickness(10, 0, 10, 0) } ); } } } 

Create custom render to align text to bottom of UITextField

Set the VerticalAlignment property to UITextField : UIControlContentVerticalAlignment.Bottom

 using UIKit; using CustomEntrySample; using CustomEntrySample.iOS; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS; [assembly: ExportRenderer(typeof(EntryWithTopPadding), typeof(EntryWithTopPaddingCustomRenderer))] namespace CustomEntrySample.iOS { public class EntryWithTopPaddingCustomRenderer : EntryRenderer { protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) { base.OnElementChanged(e); if(Control == null) return; Control.VerticalAlignment = UIControlContentVerticalAlignment.Bottom; } } } 
+5
source share

Use this to indent the input cell:

Filling in iOS:

 Control.LeftView = new UIView(new CGRect(0,15,0,0)); Control.LeftViewMode = UITextFieldViewMode.Always; Control.RightView = new UIView(new CGRect(0,10, 0, 0)); Control.RightViewMode = UITextFieldViewMode.Always; 

Android Upholstery:

 Control.SetPadding(0, 10, 0, 0); 

Accordingly, you can set the value so that the text starts from a certain position.

0
source share

All Articles