我试图自定义UISearchBar有顶部边框(或阴影),也应该是矩形:
这就是我所拥有的:
不幸的是,这段代码并不适合它:
var textField = searchbar.ValueForKey(new NSString("_searchField")) as UITextField;
if (textField != null)
{
textField.Font = UIFont.FromName("E+H_SansReg.ttf", 18);
var topBorder = new CALayer();
topBorder.Frame = new CGRect(0.0f, textField.Frame.Size.Height - 3, textField.Frame.Size.Width, 1.0f);
topBorder.BackgroundColor = UIColor.Black.CGColor;
textField.Layer.AddSublayer(topBorder);
textField.Layer.MasksToBounds = true;
}