我想添加一個(自定義的圓角半徑爲25.0)的UIButton,將鼠標懸停在我的視圖控制器中的鍵盤上方。Swift:以編程方式在鍵盤上方添加UIButton
我曾嘗試但添加該按鈕,工具欄用下面的代碼,我自己完成這一點,我不是在尋找一個工具欄:
let toolbar = UIToolbar(frame: CGRectMake(0, 0, self.view.frame.size.width, 50))
toolbar.barStyle = UIBarStyle.Default
loginButton.titleLabel?.textColor = UIColor.whiteColor()
loginButton.backgroundColor = UIColor.redColor()
loginButton.titleLabel?.text = "Sign Up"
loginButton.addTarget(self, action: #selector(signUp), forControlEvents: .TouchUpInside)
let customButton = UIBarButtonItem(customView: loginButton)
toolbar.items = [customButton]
toolbar.sizeToFit()
//...
//When credentials are valid, show/enable button...
usernameEmailField.inputAccessoryView = toolbar
我如何添加一個UIButton徘徊一直在鍵盤上方?
謝謝。
您應該瞭解如何添加鍵盤配件。以下鏈接可能會有所幫助:https://developer.apple.com/library/ios/samplecode/KeyboardAccessory/Introduction/Intro.html http://stackoverflow.com/questions/27573045/how-do-i-create- a-keyboard-accessory-view-with-auto-layout-in-interface-builder – iMuzahid