去掉UISearchBar下的1px边框

发布于 2024-11-27 04:11:41 字数 269 浏览 1 评论 0原文

UISearchBar 1px black border

我无法直接删除 UISearchBar 视图下的 1px 边框。现在它看起来与我的完成按钮视图不匹配。我试过了:

searchBar.layer.borderWidth = 0;
searchBar.layer.shadowOpacity = 0;

但这似乎不起作用。有什么想法吗?

UISearchBar 1px black border

I'm having trouble removing that 1px border directly under the UISearchBar view. Now it doesn't look matched up with my done button view. I've tried:

searchBar.layer.borderWidth = 0;
searchBar.layer.shadowOpacity = 0;

But that doesn't seem to be working. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

×纯※雪 2024-12-04 04:11:41

没关系,我刚刚做到了:

searchBar.layer.borderWidth = 1;
searchBar.layer.borderColor = [[UIColor whiteColor] CGColor];

而且它有效!

Nevermind, I just did:

searchBar.layer.borderWidth = 1;
searchBar.layer.borderColor = [[UIColor whiteColor] CGColor];

and it works!

忆依然 2024-12-04 04:11:41
[searchBar setBackgroundImage:[UIImage new]];
[searchBar setBackgroundImage:[UIImage new]];
街角卖回忆 2024-12-04 04:11:41

对于 Swift 版本,在 iOS9 上测试:

searchBar.backgroundImage = UIImage() 

它会显示如下:

no-border-result

For Swift version, tested on iOS9:

searchBar.backgroundImage = UIImage() 

It would show like this:

no-border-result

三生殊途 2024-12-04 04:11:41

为了在 Xamarin Forms 中克服此问题,您需要为 SearchBar 类创建一个 CustomRenderer
像这样:

using System;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using MyProject.iOS;

[assembly: ExportRenderer(typeof(SearchBar), typeof(CustomSearchBarRenderer))]
namespace MyProject.iOS
{
    public class CustomSearchBarRenderer:SearchBarRenderer
    {
        protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.SearchBar> e)
        {
            base.OnElementChanged (e);
            if (this.Control == null) return;

            this.Control.BackgroundImage = new UIKit.UIImage ();
        }
    }
}

In order to overcome this in Xamarin Forms, you'll need to create a CustomRenderer to the SearchBar class.
Like this:

using System;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using MyProject.iOS;

[assembly: ExportRenderer(typeof(SearchBar), typeof(CustomSearchBarRenderer))]
namespace MyProject.iOS
{
    public class CustomSearchBarRenderer:SearchBarRenderer
    {
        protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.SearchBar> e)
        {
            base.OnElementChanged (e);
            if (this.Control == null) return;

            this.Control.BackgroundImage = new UIKit.UIImage ();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文