gpt4 book ai didi

Xamarin Forms Searchbar iOS 13 忽略背景颜色

转载 作者:行者123 更新时间:2023-12-04 18:55:25 25 4
gpt4 key购买 nike

似乎最新版本的 iOS (13) 忽略了搜索栏背景颜色?

iOS 13 Changes to UISearchBar tint's, can't achieve the same outcome

我正在使用它,它适用于以下所有版本,但在 13 上它会忽略背景颜色并使其变为白色

  <SearchBar HeightRequest="35" BackgroundColor="#2A4880" TextColor="White"></SearchBar>

这是一个已知的问题?有解决办法吗?

最佳答案

您可以通过创建 PlatformEffect 来解决这个问题。 :

App.xaml.cs

[assembly: ResolutionGroupName("ProjectName")]
namespace ProjectName.App
{
public partial class App : Application
{
...

共享项目:
public class SearchBarBackgroundEffect : RoutingEffect
{
public SearchBarBackgroundEffect() : base("ProjectName.SearchBarBackgroundEffect") { }
}

iOS项目:

[assembly: ExportEffect(typeof(SearchBarBackgroundPlatformEffect), "SearchBarBackgroundEffect")]
public class SearchBarBackgroundPlatformEffect : PlatformEffect
{
private UISearchBar NativeSearchBar => (UISearchBar)Control;
private SearchBar XamarinSearchBar => (SearchBar)Element;

protected override void OnAttached()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
NativeSearchBar.SearchTextField.BackgroundColor = XamarinSearchBar.BackgroundColor.ToUIColor();
}

protected override void OnDetached()
{
// Intentionally left blank.
}
}

XAML 文件
 <SearchBar>
<SearchBar.Effects>
<effects:SearchBarBackgroundEffect />
</SearchBar.Effects>
</SearchBar>

关于Xamarin Forms Searchbar iOS 13 忽略背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58277385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com