有两种方法可以实现此目的:
ConainerType
asOutlined
<inputLayout:SfTextInputLayout
Hint="Name"
ContainerType="Outlined">
<Entry/>
</inputLayout:SfTextInputLayout>
Run Code Online (Sandbox Code Playgroud)
Label
在Frame
周围Entry
自定义渲染器以删除本机轮廓Entry
原生轮廓将被删除。
安卓
public class NoOutlineEntryRenderer : EntryRenderer
{
public NoOutlineEntryRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
this.Control.Background = null;
}
}
Run Code Online (Sandbox Code Playgroud)
iOS系统
public class NoOutlineEntryRenderer : EntryRenderer
{
public NoOutlineEntryRenderer()
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
this.Control.BorderStyle = UIKit.UITextBorderStyle.None;
}
}
Run Code Online (Sandbox Code Playgroud)
XAML
将 aFrame
和a 放在同一个Label
后面Entry
Grid
<Grid>
<Frame
BorderColor="Blue"
CornerRadius="5"
HasShadow="False"/>
<Label
x:Name="fancyEntryLabel"
AnchorY="1"
AnchorX="0"
Margin="10"
Padding="3"
TextColor="Blue"
BackgroundColor="White"
HorizontalOptions="Start"
Text="Some text"/>
<local:NoOutlineEntry
x:Name="fancyEntry"
BackgroundColor="Transparent"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
翻译Entry
焦点变化
fancyEntry.Focused += FancyEntry_Focused;
fancyEntry.Unfocused += FancyEntry_Unfocused;
... ...
private void FancyEntry_Unfocused(object sender, FocusEventArgs e)
{
if (string.IsNullOrEmpty(fancyEntry.Text))
{
fancyEntryLabel.ScaleXTo(1);
fancyEntryLabel.ScaleYTo(1);
fancyEntryLabel.TranslateTo(0, 0);
}
}
private void FancyEntry_Focused(object sender, FocusEventArgs e)
{
fancyEntryLabel.ScaleYTo(0.8);
fancyEntryLabel.ScaleXTo(0.5);
fancyEntryLabel.TranslateTo(0, -(fancyEntryLabel.Height));
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
归档时间: |
|
查看次数: |
1808 次 |
最近记录: |