gpt4 book ai didi

Swift 呈现 ViewController 键盘

转载 作者:行者123 更新时间:2023-11-28 15:46:56 25 4
gpt4 key购买 nike

我正在使用 Google places API 并以编程方式呈现 View Controller 。

它有一个搜索栏,当 View 出现时自动选择,当 View 出现时标准浅灰色键盘出现。

使用下面的代码,我将如何在呈现的 viewController 中将键盘设置为“深色”?

var opened: String = "NO"

class selectAddress: UIViewController {

// Present the Autocomplete view controller when the button is pressed.
//@IBAction func autocompleteClicked(_ sender: UIButton) {

override func viewDidAppear(_ animated: Bool) {



let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self



autocompleteController.tableCellBackgroundColor = UIColor(red: CGFloat(35/255.0), green: CGFloat(35/255.0), blue: CGFloat(43/255.0), alpha: 1.0)

autocompleteController.primaryTextColor = UIColor.gray
autocompleteController.tableCellSeparatorColor = UIColor.white
autocompleteController.primaryTextHighlightColor = UIColor.white
autocompleteController.secondaryTextColor = UIColor.gray
GMSAutocompleteViewController().tableCellSeparatorColor = UIColor.white

let filter = GMSAutocompleteFilter()
filter.type = .establishment //suitable filter type
//filter.country = "GB" //appropriate country code
autocompleteController.autocompleteFilter = filter

let barTint = UINavigationBar.appearance()
barTint.barTintColor = UIColor(red: CGFloat(48/255.0), green: CGFloat(48/255.0), blue: CGFloat(59/255.0), alpha: 1.0)





if opened == "NO" {
self.present(autocompleteController, animated: true, completion: nil)
opened = "YES"
}else{
opened = "NO"
performSegue(withIdentifier: "venueSave", sender: self)


}
// }
}
}

extension selectAddress: GMSAutocompleteViewControllerDelegate {



// Handle the user's selection.
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: \(place)")
print("Place address: \(place.formattedAddress)")
print("Place attributions: \(place.attributions)")
print("Longitude: \(place.coordinate.longitude)")
print("Latitude: \(place.coordinate.latitude)")
print("Address components: \(place.addressComponents)")


let city = place.addressComponents?[2].name

print("CITYYYY \(city!)")

/*
var request = URLRequest(url: URL(string: "https://www.asmserver.co.uk/barduo/addvenue.php")!)
request.httpMethod = "POST"
let postString = "name=\(facebookID!)&email=\(email!)&firstname=\(firstName!)&lastname=\(lastName!)&link=\(link!)"
print(postString)
request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else { // check for fundamental networking error
print("error=\(error)")
return
}

if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { // check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(response)")
}

let responseString = String(data: data, encoding: .utf8)

print("*****\(responseString!)")

defaults.set("\(responseString!)", forKey: "id")

DispatchQueue.main.async {
self.performSegue(withIdentifier: "goNext", sender: self)
}

}
task.resume()

*/

dismiss(animated: true, completion: nil)

}



func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
// TODO: handle the error.
print("Error: ", error.localizedDescription)
}

// User canceled the operation.
func wasCancelled(_ viewController: GMSAutocompleteViewController) {
dismiss(animated: true, completion: nil)
}

// Turn the network activity indicator on and off again.
func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
}

func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}

func viewController(viewController: GMSAutocompleteViewController!, didFailAutocompleteWithError error: NSError!) {
// TODO: handle the error.
print("Error: ", error.description)
}

}

最佳答案

我使用了以下行:

UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).keyboardAppearance = .dark

关于Swift 呈现 ViewController 键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42886701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com