How to add dot in Number Pad Keyboard? I want when I use notification UIKeyboardDidShowNotification a UIButton to appear over down left side of the Number Pad keyboard.
This will be the frame of the button:
let dotButton = UIButton(frame: CGRectMake(0, 162, view.frame.width/3, 54))
,
but it has to be added as subview of the number pad keyboard to prevent hiding from it, how will be done ?
Edit: I made it to appear like this
dotButton.addTarget(self, action: "addDot:", forControlEvents: .TouchUpInside)
dotButton.setTitle(".", forState: .Normal)
dotButton.titleLabel?.font = UIFont(name: "Helvetica Neue", size: 25)
dotButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
dispatch_async(dispatch_get_main_queue(), {
let keyboardView:UIView = UIApplication.sharedApplication().windows.last?.subviews.first as! UIView
self.dotButton.frame = CGRectMake(0, keyboardView.frame.size.height-54, self.view.frame.width/3, 54)
keyboardView.addSubview(self.dotButton)
keyboardView.bringSubviewToFront(self.dotButton)
})
but now I don't know how when I click to the button to add . in the textField with method addDot I don't know how to tell to the textField to add a . need help again...
Edit2:
I made a class variable which is textFieldInEdit:UITextField!
and in func textFieldShouldBeginEditing(textField: UITextField) -> Bool
I do this textFieldInEdit = textField
and now my function addDot
is:
textFieldWhichEdit.text = "\(textFieldWhichEdit.text)."
,
but I've got another problem now.. I have fields with different keyboard types how to detect which keyboard appears and show the dot on the Number Pad only ?
Edit3:
func textFieldDidBeginEditing(textField: UITextField) {
if(textField.keyboardType.rawValue==4){
textFieldWhichEdit = textField
dotButton.hidden = false
}else{
dotButton.hidden = true
}
}
Done I've made a dot button on Number Pad keyboard :) If someone know better method can write it and I will accept the answer :)
yourTextField.keyboardType = .decimalPad
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With