ios - 如何让Android特定代码兼容IOS?

标签 ios xamarin xamarin.android xamarin.ios compatibility

<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/

相关文章:

ios - href=电话 :555 link not working in mobile safari

android - 从Android中的内存流播放WAV音频

C# 从 EC 公钥字节生成 PublicKey/IPublicKey 对象?

c# - 延迟几秒多次更新 Textview 文本

iphone - 应用程序启动时,iPhone 的phonegap 应用程序不会从主页启动

ios - 大 double ,格式为带有点的 NSString

android - 罢工 html 标签不呈现在 EditText 与 TextFormatted

c# - 从 Xamarin Forms UWP 中的 Webview 获取内容高度

Xamarin Android 应用程序消耗异常大量的电池。为什么?

ios - 在 Swift 中根据 String 计算出 UILabel 的大小