Implement the Finish button in iOS in the top right corner of the keyboard

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.