IOS 8 keyboard how to swap between the decimal and numeric keyboard + shift key -
i busy making ios 8 keyboard , need help.
i have made basic keyboard , works fine have bumps , need slove them. wrote code in swift(keep in mind i'm new swift).
i need following:
to swap keyboard decimal(the normal 1 letters) numeric(the number/symbol one) wrote code (it hides keyboards respectively , shows them again) don't know how make run when tap "123" button.
when type key eg. "a" prints out how appears on keyboard how can make automatically lowercase , implement shift button give me capital letters?
some solve appreciated.
here code have far:
import uikit class keyboardviewcontroller: uiinputviewcontroller { @iboutlet var nextkeyboardbutton: uibutton! var allbuttons = [uibutton]() override func updateviewconstraints() { super.updateviewconstraints() // add custom view sizing constraints here } override func viewdidload() { //normal keyboard start super.viewdidload() let buttontitles1 = ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"] let buttontitles2 = ["a", "s", "d", "f", "g", "h", "j", "k", "l"] let buttontitles3 = ["⬆︎", "z", "x", "c", "v", "b", "n", "m", "⬅︎"] let buttontitles4 = ["123","🌐","⎯", "return"] //⚒ var row1 = createrowofbuttons(buttontitles1) var row2 = createrowofbuttons(buttontitles2) var row3 = createrowofbuttons(buttontitles3) var row4 = createrowofbuttons(buttontitles4) self.view.addsubview(row1) self.view.addsubview(row2) self.view.addsubview(row3) self.view.addsubview(row4) row1.settranslatesautoresizingmaskintoconstraints(false) row2.settranslatesautoresizingmaskintoconstraints(false) row3.settranslatesautoresizingmaskintoconstraints(false) row4.settranslatesautoresizingmaskintoconstraints(false) addconstraintstoinputview(self.view, rowviews: [row1, row2, row3, row4]) applycurrenttheme() //normal keyboard end //change numeric keyboard start let buttonsnum1firstrow = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] let buttonsnum2firstrow = ["-", "/", ":", ";", "(", ")", "$", "&", "@", "\""] let buttonsnum3firstrow = ["#+=", ".", ",", "?", "!", "'", "7", "⬅︎"] let buttonsnum4firstrow = ["abc","⎯","return"] //define rows class variable instead of function variable var srow1:uiview! var srow2:uiview! var srow3:uiview! var srow4:uiview! var srow1num:uiview! //hide below: func didtapchangetonumbersbutton(sender: anyobject?) { srow1.hidden = true srow1num.hidden = false } //change numeric keyboard end } func createrowofbuttons(buttontitles: [nsstring]) -> uiview { var buttons = [uibutton]() var keyboardrowview = uiview(frame: cgrectmake(0, 0, 320, 50)) buttontitle in buttontitles { let button = createbuttonwithtitle(buttontitle) buttons.append(button) keyboardrowview.addsubview(button) } allbuttons += buttons addindividualbuttonconstraints(buttons, mainview: keyboardrowview) return keyboardrowview } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated } override func textwillchange(textinput: uitextinput) { // app change document's contents. perform preparation here. } override func textdidchange(textinput: uitextinput) { // app has changed document's contents, document context has been updated. var textcolor: uicolor var proxy = self.textdocumentproxy uitextdocumentproxy if proxy.keyboardappearance == uikeyboardappearance.dark { textcolor = uicolor.whitecolor() } else { textcolor = uicolor.blackcolor() } } func createbuttonwithtitle(title: string) -> uibutton { let button = uibutton.buttonwithtype(.system) uibutton button.frame = cgrectmake(0, 0, 20, 20) button.settitle(title, forstate: .normal) button.sizetofit() button.titlelabel?.font = uifont.systemfontofsize(10) button.settranslatesautoresizingmaskintoconstraints(false) button.backgroundcolor = uicolor(white: 1.0, alpha: 1.0) button.settitlecolor(uicolor.darkgraycolor(), forstate: .normal) button.addtarget(self, action: "didtapbutton:", forcontrolevents: .touchupinside) return button } func didtapbutton(sender: anyobject?) { let button = sender uibutton var proxy = textdocumentproxy uitextdocumentproxy let capon = false; let capslast = false; let capslock = false; let spacelast = false; if let title = button.titleforstate(.normal) { switch title { case "🌐" : self.advancetonextinputmode() case "." : let capon = true proxy.inserttext(".") let spacelast = false let capslast = false //caps idea //this caps lock code experimental , doesn't work, idea playing case "⬆︎" : let capon = !capon if capslock { let capon = true let capslock = false let capslast = false } let capslast = true //caps idea case "⬅︎" : proxy.deletebackward() let spacelast = false let capslast = false case "return" : proxy.inserttext("\n") let spacelast = false let capslast = false case "⎯" : if spacelast { proxy.deletebackward() proxy.inserttext(". ") let spacelast = false let capon = true } else { proxy.inserttext(" ") let spacelast = true } let capslast = false default : proxy.inserttext(title) } } } func applycurrenttheme() { var theme = claptontheme() theme.applythemetoview(self.view) theme.applythemetokeys(allbuttons) } func addindividualbuttonconstraints(buttons: [uibutton], mainview: uiview) { (index, button) in enumerate(buttons) { var topconstraint = nslayoutconstraint(item: button, attribute: .top, relatedby: .equal, toitem: mainview, attribute: .top, multiplier: 1.0, constant: 1) var bottomconstraint = nslayoutconstraint(item: button, attribute: .bottom, relatedby: .equal, toitem: mainview, attribute: .bottom, multiplier: 1.0, constant: -1) var rightconstraint : nslayoutconstraint! if index == buttons.count - 1 { rightconstraint = nslayoutconstraint(item: button, attribute: .right, relatedby: .equal, toitem: mainview, attribute: .right, multiplier: 1.0, constant: -1) } else { let nextbutton = buttons[index+1] rightconstraint = nslayoutconstraint(item: button, attribute: .right, relatedby: .equal, toitem: nextbutton, attribute: .left, multiplier: 1.0, constant: -1) } var leftconstraint : nslayoutconstraint! if index == 0 { leftconstraint = nslayoutconstraint(item: button, attribute: .left, relatedby: .equal, toitem: mainview, attribute: .left, multiplier: 1.0, constant: 1) } else { let prevtbutton = buttons[index-1] leftconstraint = nslayoutconstraint(item: button, attribute: .left, relatedby: .equal, toitem: prevtbutton, attribute: .right, multiplier: 1.0, constant: 1) let firstbutton = buttons[0] var widthconstraint = nslayoutconstraint(item: firstbutton, attribute: .width, relatedby: .equal, toitem: button, attribute: .width, multiplier: 1.0, constant: 0) widthconstraint.priority = 800 mainview.addconstraint(widthconstraint) } mainview.addconstraints([topconstraint, bottomconstraint, rightconstraint, leftconstraint]) } } func addconstraintstoinputview(inputview: uiview, rowviews: [uiview]) { (index, rowview) in enumerate(rowviews) { var rightsideconstraint = nslayoutconstraint(item: rowview, attribute: .right, relatedby: .equal, toitem: inputview, attribute: .right, multiplier: 1.0, constant: -1) var leftconstraint = nslayoutconstraint(item: rowview, attribute: .left, relatedby: .equal, toitem: inputview, attribute: .left, multiplier: 1.0, constant: 1) inputview.addconstraints([leftconstraint, rightsideconstraint]) var topconstraint: nslayoutconstraint if index == 0 { topconstraint = nslayoutconstraint(item: rowview, attribute: .top, relatedby: .equal, toitem: inputview, attribute: .top, multiplier: 1.0, constant: 0) } else { let prevrow = rowviews[index-1] topconstraint = nslayoutconstraint(item: rowview, attribute: .top, relatedby: .equal, toitem: prevrow, attribute: .bottom, multiplier: 1.0, constant: 0) let firstrow = rowviews[0] var heightconstraint = nslayoutconstraint(item: firstrow, attribute: .height, relatedby: .equal, toitem: rowview, attribute: .height, multiplier: 1.0, constant: 0) heightconstraint.priority = 800 inputview.addconstraint(heightconstraint) } inputview.addconstraint(topconstraint) var bottomconstraint: nslayoutconstraint if index == rowviews.count - 1 { bottomconstraint = nslayoutconstraint(item: rowview, attribute: .bottom, relatedby: .equal, toitem: inputview, attribute: .bottom, multiplier: 1.0, constant: 0) } else { let nextrow = rowviews[index+1] bottomconstraint = nslayoutconstraint(item: rowview, attribute: .bottom, relatedby: .equal, toitem: nextrow, attribute: .top, multiplier: 1.0, constant: 0) } inputview.addconstraint(bottomconstraint) } } }
Comments
Post a Comment