ios - 如何在 iOS 中设置 Xamarin.Forms SearchBar 的样式?

标签 ios xamarin xamarin.forms

我正在尝试设置 Xamarin.Forms SearchBar 的样式,我可以看到有一个 BackgroundColor 属性,但是无论我设置什么,该属性在 iOS 中都会被忽略。

是否可以在 iOS 中自定义 Xamarin.Forms SearchBar(以及如何自定义)?

最佳答案

不幸的是,我无法获得公认的工作答案。尽管适用于 iOS,但下面的代码确实对我有用。请注意,OnElementChanged 而不是 Draw 似乎是将此类内容放入自定义渲染器的首选位置。

using MonoTouch.UIKit;

using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly:ExportRenderer( typeof(MyNamespace.MySearchBar), typeof(MyNamespace.iOS.MySearchBarRenderer_iOS))]


namespace MyNamespace.iOS
{
    public class MySearchBarRenderer_iOS : SearchBarRenderer
    {
        protected override void OnElementChanged( ElementChangedEventArgs<SearchBar> args )
        {
            base.OnElementChanged( args );

            UISearchBar bar = (UISearchBar)this.Control;

            bar.AutocapitalizationType = UITextAutocapitalizationType.None;
            bar.AutocorrectionType = UITextAutocorrectionType.No;
            bar.BarStyle = UIBarStyle.Default;
            bar.BarTintColor = UIColor.Green;
            bar.KeyboardType = UIKeyboardType.ASCIICapable;
        }
    }
}

关于ios - 如何在 iOS 中设置 Xamarin.Forms SearchBar 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24390869/

相关文章:

ios - 使用 Google Calendar API 加载库 - Obj C

xamarin - 如何在 Windows 上为 Xamarin.iOS 进行符号化

xamarin - 从 Xamarin 表单触发 native View 事件

xamarin.forms - 无法在 Xamarin.Forms 项目中同时使用 Mobile FFmpeg 和 LibVLCSharp

ios - Swift - xib 中不需要的边距

ios - 我想查看静态表格 View 中的所有单元格,这些单元格不会出现在故事​​板的屏幕上

ios - 在 UItableviewcell 中创建标签

c# - 无效的 il 代码 System.IO.Compression.ZipFile.OpenRead() 方法主体为空

c# - 在 axml 中使用来自 pcl 的 resx 字符串?

Xamarin Forms - 如何在应用程序关闭时单击通知后打开特定页面?