UISearchBar添加顶部边框

时间:2018-06-12 14:57:59

标签: xamarin xamarin.ios uitextfield uisearchbar calayer

我试图自定义UISearchBar有顶部边框(或阴影),也应该是矩形:

这就是我所拥有的:

enter image description here

这是我想要的: enter image description here

不幸的是,这段代码并不适合它:

            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;
            }

0 个答案:

没有答案