简体   繁体   English

如何去除 UISearchbar 的边框?

[英]How to remove border of UISearchbar?

As per as design I tried to remove the border of uisearchbar but failed.根据设计,我尝试删除 uisearchbar 的边框但失败了。 can you please help or suggest?你能帮忙或建议吗?

在此处输入图片说明

I want to create like below design.我想创建如下设计。

在此处输入图片说明

If this custom search bar?如果这个自定义搜索栏? Mb you need something like this: Mb 你需要这样的东西:

searchBar.backgroundImage = [UIImage new];

This removes background.这将删除背景。 And after this set this:在此设置之后:

searchBar.barTintColor = [UIColor whiteColor];

Or mb you are need to try this:或者 mb 你需要试试这个:

searchBar.layer.borderColor = [[UIColor YOUR_COLOR_HERE] CGColor];

And another case:还有一个案例:

topSearchBar.barTintColor = [UIColor clearColor];

Mb this help you Mb 这对你有帮助

After the trial, I found a solution which is working for me.试用后,我找到了一个对我有用的解决方案。 I set the color like super view's color.我将颜色设置为超级视图的颜色。 That's why it is not visible and then I wrote some lines of code in viewDidLoad().这就是为什么它不可见,然后我在 viewDidLoad() 中编写了一些代码行。

    override func viewDidLoad() {

        super.viewDidLoad()

        searchBar.backgroundImage = UIImage()
        searchBar.delegate = self
        let textFieldInsideSearchBar = searchBar.value(forKey: "searchField") as? UITextField
        textFieldInsideSearchBar?.textColor = UIColor.black
        textFieldInsideSearchBar?.leftViewMode = UITextFieldViewMode.never
    }

在此处输入图片说明

To obtain this design make below changes in storyboard.要获得此设计,请在故事板中进行以下更改。

在此处输入图片说明

and

在此处输入图片说明

then add below code into your viewdidload or whatever you want.然后将以下代码添加到您的viewdidload或您想要的任何内容中。

self.bar.layer.cornerRadius = self.bar.frame.height/2
    self.bar.layer.masksToBounds = true

then I think you will get your desire design.let me know if it works or not .那么我想你会得到你想要的设计。让我知道它是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM