【发布时间】:2020-04-22 00:43:01
【问题描述】:
这是我的第一篇文章,不要讨厌我。这种情况解释起来很复杂,但我会尽量说清楚。我有一个 xamarin 形式的项目,我正在开发 iOS 版本,我将字体从基本字体更改为 Nexa。这导致改变了“g”的大小并产生了我无法解决的问题。我有一个用于条目的自定义渲染器,但我没有在网上找到任何方法来纠正底部填充。我已经在页面的 xaml、自定义渲染器和样式上尝试了许多更改,但没有解决问题 https://github.com/xamarin/Xamarin.Forms/issues/6141 。我也读过这个,但它对我没有帮助。在这里我写我的代码来澄清情况:
风格:
<!-- 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 页面:
<Frame Style="{StaticResource FrameEntry}">
<cr:BorderlessEntry Placeholder="{x:Static res:AppResources.PLACE}" Text="{Binding Place}"/>
</Frame>
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;
}
}
很明显,如果我尝试在条目中写 g 它不会被删减!
我还发现按钮内的文本也出现了同样的问题,您可以在链接的测试项目中找到这两个示例。
这里是重新创建问题的测试项目的链接(仅在 iOS 上)
https://drive.google.com/open?id=1J2FAbh_jjJ8JnURh_-C7jBXbr02xBBGD
【问题讨论】:
-
您的描述含糊不清。所以您能否分享一个包含该问题的示例,以便我可以测试它。
-
更新示例链接
-
权限问题无法下载,你可以上传到github。
-
现在我修复了下载,我也修复了按钮
标签: c# xaml xamarin mvvm xamarin.ios