无法更改其中的搜索栏和文本字段的高度

时间:2018-09-06 15:17:16

标签: ios swift xcode

func configureSearchController()
    {

        resultsController.tableView.delegate = self
        resultsController.tableView.dataSource = self

        self.searchController = UISearchController(searchResultsController: self.resultsController)
        //self.tableView.tableHeaderView = self.searchController.searchBar
        self.searchController.searchResultsUpdater = self

        self.searchController.dimsBackgroundDuringPresentation = false
        self.searchController.searchBar.sizeToFit()
        searchController.searchBar.delegate = self
        self.searchController.searchBar.scopeButtonTitles = []


        for subView in searchController.searchBar.subviews {
            for subViewOne in subView.subviews {
                if subViewOne is UITextField {
                    searchTextField = subViewOne as! UITextField
                    subViewOne.backgroundColor = UIColor.white

                    var currentTextFieldBounds = subViewOne.bounds
                    currentTextFieldBounds.size.height = 45
                    subViewOne.bounds = currentTextFieldBounds
                    break
                }
            }
        }


        extendedLayoutIncludesOpaqueBars = true
        definesPresentationContext = true

    }

这不会意外更改文本字段的高度。我也想更改搜索栏的高度。我应该在此处进行哪些更改以使它们起作用?

1 个答案:

答案 0 :(得分:1)

IMO,不应更改搜索栏的大小,因为它是Apple提供的本机标准。另外,不建议您使用递归搜索文本字段的方式,也不保证在所有iOS版本中都可以使用。

也许您可以尝试将自定义搜索栏与您自己的文本字段一起使用,并且您可以轻松地使用它。

相关问题