1, creation of multi-line text controls
1234 |
let textview = 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 |
import
UIKit
class
ViewController
:
UIViewController
{
override
func
viewDidLoad() {
super
.viewDidLoad()
let
textview =
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)
let
mail =
UIMenuItem
(title:
"邮件"
, action: #selector(
ViewController
.onMail))
let
weixin =
UIMenuItem
(title:
""
, action: #selector(
ViewController
.onWeiXin))
let
menu =
UIMenuController
()
menu.menuItems = [mail,weixin]
}
func
onMail(){
print
(
"mail"
)
}
func
onWeiXin(){
print
(
"weixin"
)
}
override
func
didReceiveMemoryWarning() {
super
.didReceiveMemoryWarning()
}
}
|
PS: Apple official website Api:uitextview
Swift-Multiline text input box (Uitextview)