'Placeholder Margin on Xamarin Forms Editor using Custom Renderer
I've an Editor on a page in my Xamarin Forms Project and I'm looking to amend the placeholder text position by adding a slight margin.
I was able to add a margin to the text the user types (but not the placeholder) using "TextContainerInset" in my iOS Custom renderer.
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
this.Control.InputAccessoryView = null;
this.Control.Layer.CornerRadius = 10;
this.Control.Layer.BorderColor = UIColor.LightGray.CGColor;
this.Control.Layer.BorderWidth = (nfloat)0.5;
this.Control.TextContainerInset = new UIEdgeInsets(15,15,15,15);
}
However, this inset doesn't apply to the placeholder position.
Is there a way to move the placeholder position using the custom renderer?
Solution 1:[1]
You could set the padding like:
public class MyEntryRenderer : 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;
Control.RightView = new UIView(new CGRect(0, 0, 15, 0));
Control.RightViewMode = UITextFieldViewMode.Always;
}
}
}
Workaournd for editor:
warp the editor in the frame and set the padding like:
<StackLayout Margin="20">
<Frame CornerRadius="10" BorderColor="Gray" HeightRequest="50" Padding="5,10,5,10" HasShadow="False">
<Editor Placeholder="Enter the editor text" ></Editor>
</Frame>
</StackLayout>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
