<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="1dp" android:color="#e7e7e7" />
<solid android:color="#fafafa" />
<padding android:left="1dp" android:right="1dp" android:top="1dp" />
<corners android:radius="30dp" />
</shape>
上面的自定义渲染器的 Xml 代码。
public class CustomRoundedEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Background = Android.App.Application.Context.GetDrawable(Resource.Drawable.RoundedEntry);
Control.Gravity = GravityFlags.CenterVertical;
Control.SetPadding(10, 0, 0, 0);
}
}
}
Android 解决方案中的自定义渲染器代码。
这里需要的是该代码应该兼容并且也可以在 iOS 平台上运行。
最佳答案
您似乎想使用自定义渲染器来设置 Entry 的边框和角。
对于iOS,您可以检查以下代码
public class MyEntryRenderer:EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if(Control!=null)
{
Control.Layer.MasksToBounds = true;
//border and corner
Control.Layer.BorderColor = Color.FromHex("#e7e7e7").ToCGColor();
Control.Layer.BorderWidth = 1;
Control.Layer.CornerRadius = 30;
//padding
UIView padView = new UIView() {Frame = new CGRect(0,0,10,1)};
Control.LeftViewMode = UITextFieldViewMode.Always;
Control.LeftView = padView;
}
}
关于ios - 如何让Android特定代码兼容IOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59542033/