public static void SetTextFieldBackgroundColor(this UISearchBar searchBar, UIColor color) { var backgroundView = searchBar.GetTextField()?.Subviews.FirstOrDefault(); if (backgroundView == null) { return; } foreach (var subview in backgroundView.Subviews) { subview.RemoveFromSuperview(); } backgroundView.BackgroundColor = color; backgroundView.Layer.CornerRadius = 10; backgroundView.ClipsToBounds = true; }