Import Uikitclass Uitextfieldx:uitextfield {override func DrawRect (rect:cgrect) {super.drawrect (rect) Keyboard Completion button var ToolBar = Uitoolbar (frame:cgrectmake (0, 0, screensize (). width, ()) Toolbar.barstyle = uibarstyle.default var btnfished = UIButton (frame:cgrectmake (0, 0, +)) Btnfished.settitleco Lor (RGB (4, 174), ForState:UIControlState.Normal) Btnfished.settitlecolor (Uicolor.graycolor (), Forstate:uicon trolstate.highlighted) Btnfished.settitle ("Done", ForState:UIControlState.Normal) Btnfished.addtarget (self, a Ction: "finishtapped:", forControlEvents:UIControlEvents.TouchUpInside) var item2 = Uibarbuttonitem (customview:bt nfished) var space = UIView (frame:cgrectmake (0, 0, screensize (). width-btnfished.frame.width-30, 25)) var item = Uibarbuttonitem (customview:space) Toolbar.setitems ([item,item2], Animated:true) Self.inputaccessoRyview = ToolBar} func finishtapped (Sender:uibutton) {self.resignfirstresponder ()}}func screensize () -cgsize{return Uiscreen.mainscreen (). Bounds.size}func RGB (r:cgfloat, G:cgfloat, b:cgfloat), Uicolor {R Eturn Uicolor (red:r/255.0, green:g/255.0, blue:b/255.0, Alpha:1)}
The effect is as follows:
Implement the Finish button in iOS in the top right corner of the keyboard