简体   繁体   English

Xamarin Forms iOS CustomRenderer 条目占位符和按钮文本填充底部

[英]Xamarin Forms iOS CustomRenderer Entry PlaceHolder And Button Text Padding Bottom

问题画面

It's my first post, don't hate me.这是我的第一篇文章,不要讨厌我。 The situation is complicated to explain but I will try to be as clear as possible.情况很难解释,但我会尽量说清楚。 I have a project in xamarin forms and I'm working on the iOS build, I changed the font from the base one to Nexa.我有一个 xamarin 形式的项目,我正在开发 iOS 版本,我将字体从基本字体更改为 Nexa。 This led to change the size of the "g" and to create this problem that I am not able to solve.这导致更改“g”的大小并产生我无法解决的问题。 I have a custom renderer for the entries but I have not found any way on the net to correct the bottom padding.我有一个用于条目的自定义渲染器,但我还没有在网上找到任何方法来纠正底部填充。 I have already tried many changes on the xaml of the page, on the custom renderer and on the style without solving the problem https://github.com/xamarin/Xamarin.Forms/issues/6141 .我已经在页面的 xaml、自定义渲染器和样式上尝试了许多更改,但没有解决问题https://github.com/xamarin/Xamarin.Forms/issues/6141 I also read this but it didn't help me.我也读过这个,但它对我没有帮助。 Here I write my code to clarify the situation:在这里我写我的代码来澄清情况:

Style :风格 :

<!-- Default Entries -->
    <Style TargetType="cr:BorderlessEntry">
        <Setter Property="HeightRequest" Value="45"/>
        <Setter Property="TextColor" Value="Black"/>
        <Setter Property="PlaceholderColor" Value="Gray"/>
        <Setter Property="FontFamily" Value="{StaticResource NormalFont}"/>
    </Style>
<!-- Default Frame -->
    <Style x:Key="FrameEntry" TargetType="Frame">
        <Setter Property="BorderColor" Value="{StaticResource LightBlue}"/>
        <Setter Property="CornerRadius" Value="25"/>
        <Setter Property="Padding" Value="10,3,10,3"/>
        <Setter Property="Margin" Value="0"/>
    </Style>

Xaml Page: Xaml 页面:

<Frame Style="{StaticResource FrameEntry}">
    <cr:BorderlessEntry Placeholder="{x:Static res:AppResources.PLACE}" Text="{Binding Place}"/>
</Frame>

CS Custom Renderer: CS自定义渲染器:

   public class BorderlessEntryRenderer : EntryRenderer
    {
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (Control == null)
                return;

            Control.Layer.BorderWidth = 0;
            Control.BorderStyle = UITextBorderStyle.None;
            //Control.VerticalAlignment = UIControlContentVerticalAlignment.Fill;
            //Control.LeftView = new UIView(new CGRect(0, 0, 0, 0));
            //Control.LeftViewMode = UITextFieldViewMode.Always;
            //Control.RightView = new UIView(new CGRect(0, 0, 0, 0));
            //Control.RightViewMode = UITextFieldViewMode.Always;
        }
    }

Obviously if I try to write g inside the entry it is not cut!显然,如果我尝试在条目中写入 g ,则不会被剪切!

在这里

I also found that the same problem occurs for the text inside the buttons, you can find both examples inside the linked test project.我还发现按钮内的文本出现了同样的问题,您可以在链接的测试项目中找到这两个示例。

在此处输入图片说明

Here is the link of a test project to recreate the issue (only on iOS)这是重新创建问题的测试项目的链接(仅在 iOS 上)

https://drive.google.com/open?id=1J2FAbh_jjJ8JnURh_-C7jBXbr02xBBGD https://drive.google.com/open?id=1J2FAbh_jjJ8JnURh_-C7jBXbr02xBBGD

In the renderer's OnElementPropertyChanged set在渲染器的OnElementPropertyChanged集合中

 var unconstrainedSize = new CGSize(99999999999, 99999999999);
 Control.HeightAnchor.ConstraintEqualTo(unconstrainedSize.Height).Active = true;

You can also play with padding:您还可以使用填充:

public override void LayoutSubviews()
{

   base.LayoutSubviews();

            CGRect frame = this.top.Frame; // save frame
            frame.Height = this.Bounds.Size.Height + 20f; //modify frame
            //Frame.Offset(0, 20); dunno can play with this too
            this.Frame = frame; // set modifyed
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM