如何在xamarin.forms中为输入单元设置左右填充 [英] How to set left and right padding to an entry cell in xamarin.forms

查看:111
本文介绍了如何在xamarin.forms中为输入单元设置左右填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为IOS和android的xamarin表单中的条目单元格使用了自定义渲染。我该如何为输入单元格设置左右填充。

I have used custom rendering for entry cell in xamarin forms for IOS and android. How can I set left and right padding for the entry cell.

我在PCl中的自定义输入单元格:

My custom entry cell in PCl :

<local:MyEntryCell Placeholder="Placeholder" PlaceholderColor="Grey" TextColor="Black"/>

MyEntryCell is the custom name of my entry cell.

在我的PCL中,我有:

In my PCL I have:

public class MyEntryCell:Entry
{

}

在IOS中:

namespace CustomEntry.IOS
{
   public class MyEntryCellRenderer:EntryRenderer
    {
         // override onElementChanged
    }
}

在Android中:

namespace CustomEntry.Droid
    {
       public class MyEntryCellRenderer:EntryRenderer
        {
             // override onElementChanged
        }
    }


推荐答案

使用此方法为输入单元格设置填充:

Use this for setting padding to an entry cell:

IOS中的填充:

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;

在Android中填充:

Padding in Android:

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

因此,您可以设置值以使文本从特定位置开始。

Accordingly, you can set the value to make text start from specific position.

这篇关于如何在xamarin.forms中为输入单元设置左右填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆