更改searchBar占位符文本对齐左侧iOS swift

时间:2016-05-12 06:54:53

标签: ios iphone xcode swift

这是我的searchBar的代码

self.searchResultsController = ({
            let controller = UISearchController(searchResultsController: nil)
            controller.searchResultsUpdater = self
            controller.dimsBackgroundDuringPresentation = false
            controller.hidesNavigationBarDuringPresentation = false
            controller.searchBar.sizeToFit()
            controller.searchBar.placeholder = "Type your word here"
            //dcontroller.view.backgroundColor = UIColor.blackColor()
            controller.searchBar.barTintColor = UIColor.blackColor()

            self.tableVw.tableHeaderView = controller.searchBar

            return controller

        })()

当我点击搜索栏时,代码变为左对齐但在此之前它始终是分散的

1 个答案:

答案 0 :(得分:-7)

您可以使用whitespace来实现此目标!

  let searchBar: UISearchBar = UISearchBar()  //your searchbar
    searchBar.placeholder = "Search                  " 

希望这会有所帮助:)