[英]iOS Keyboard - Capitalise 'done' button
我正在為我的 UITextfields 使用“UIKeyboardTypeDefault”鍵盤類型。
鍵盤的完成按鈕以小寫形式顯示為“完成”。 有沒有辦法讓它大寫為“完成”?
您可以嘗試使用 POD -> IQKeyboardManagerSwift LINK -->
pod 'IQKeyboardManagerSwift', :git => ' https://github.com/hackiftekhar/IQKeyboardManager.git '
這是處理鍵盤內容的非常有用的 pod
我們無法為返回鍵設置自定義文本,我們只能從可用選項中進行選擇(請參閱隨附的屏幕截圖)。 為了設置自定義文本,例如大寫的“完成”按鈕,您必須創建一個自定義鍵盤。 附截圖
在過去的一天左右,我一直在為 tvOS 解決同樣的問題,並發現解決方案是獲取所呈現鍵盤的“to”viewController,遍歷其視圖層次結構以找到按鈕,然后獲取其文本,將其大寫,然后將其放回原處。
最終得到以下 function:
fileprivate func CapitaliseReturnKey() {
let scene = UIApplication.shared.connectedScenes.first
guard
let windowSceneDelegate = scene?.delegate as? UIWindowSceneDelegate,
let window = windowSceneDelegate.window,
// This gets the presented keyboard view, which is the 'to' view for the presentation transition.
let keyboardView = window?.rootViewController?.transitionCoordinator?.view(forKey: .to)
else {
return
}
capitaliseReturnKey(in: keyboardView)
/// Traverses the view heirarchy of the passed-in view looking for a UIButton and capitalises its title.
/// - Parameter view: the view to iterate over
func capitaliseReturnKey(in view: UIView) {
for subView in view.subviews {
if subView.subviews.count > 0 {
capitaliseReturnKey(in: subView)
}
if subView.isKind(of: UIButton.self) {
if let buttonView = subView as? UIButton {
buttonView.setTitle(buttonView.currentTitle?.localizedCapitalized, for: .normal)
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.