Xamarin.IOS自定义条目下划线较长

时间:2019-08-27 08:59:58

标签: xamarin xamarin.forms xamarin.ios

enter image description here

如何处理用户记录,使其长度与按钮匹配?

CustomEntryUnderlineRenderer.cs

OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control == null || e.NewElement == null)
                return;

            Control.BorderStyle = UITextBorderStyle.None;

            CALayer line = new CALayer
            {
                Frame = new CGRect(0, Frame.Height, Frame.Width, 1f)
            };

            Control.Layer.AddSublayer(line);
        }

Page.xaml

<StackLayout Margin="20,0">
            <Label Text="The address of your server:" FontSize="Small" FontFamily="{StaticResource RalewayNormal}" TextColor="White" HorizontalOptions="FillAndExpand"/>
            <local:CustomEntryUnderline x:Name="addressEntry" Margin="0,15,0,0" FontSize="Small" Text="http://192.168.0.217/PelicanMobile" Placeholder="Enter the server address" FontFamily="{StaticResource RalewayNormal}" TextColor="White" PlaceholderColor="White"/>
            <Button x:Name="btnAdressEnter" Text="Enter" BorderRadius="0" Clicked="OnButtonClicked_Enter" FontSize="Small" FontFamily="{StaticResource RalewayNormal}" TextColor="White" BackgroundColor="#E67E20"/>
        </StackLayout>

1 个答案:

答案 0 :(得分:0)

它将有助于解决这个问题 https://xamgirl.com/image-entry-in-xamarin-forms/