Swift-Multiline text input box (Uitextview)

Source: Internet
Author: User

1, creation of multi-line text controls
1234 lettextview = UITextView(frame:CGRect(x:10, y:100, width:200, height:100))textview.layer.borderWidth = 1  //边框粗细textview.layer.borderColor = UIColor.gray.cgColor //边框颜色self.view.addSubview(textview)
2, whether it can be edited
1 textview.isEditable = false
3, whether the content is optional
1 textview.isSelectable = false
4, attribute font set font, TextColor set font color, TextAlignment set alignment 5, give text to phone number and URL automatically link
1234 textview.dataDetectorTypes = [] //都不加链接textview.dataDetectorTypes = UIDataDetectorTypes.phoneNumber //只有电话加链接textview.dataDetectorTypes = UIDataDetectorTypes.link //只有网址加链接textview.dataDetectorTypes = UIDataDetectorTypes.all //电话和网址都加
6, customize the selection after the menu when we are watching news or novels, often after the click on the text will pop-up menu to select, copy and so on. We can add some additional content to this menu, such as the "Mail" "" button options
123456789101112131415161718192021222324252627282930 importUIKitclassViewControllerUIViewController{        overridefuncviewDidLoad() {        super.viewDidLoad()                lettextview = UITextView(frame:CGRect(x:10, y:100, width:200, height:100))        textview.layer.borderWidth = 1  //边框粗细        textview.layer.borderColor = UIColor.gray.cgColor //边框颜色        self.view.addSubview(textview)                letmail = UIMenuItem(title: "邮件", action: #selector(ViewController.onMail))        letweixin = UIMenuItem(title: "", action: #selector(ViewController.onWeiXin))        letmenu = UIMenuController()        menu.menuItems = [mail,weixin]    }        funconMail(){        print("mail")    }        funconWeiXin(){        print("weixin")    }        overridefuncdidReceiveMemoryWarning() {        super.didReceiveMemoryWarning()    }}

PS: Apple official website Api:uitextview

Swift-Multiline text input box (Uitextview)

Related Article

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: info-contact@alibabacloud.com 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.