Swift - 多行文本输入框(UITextView)的用法

前端之家收集整理的这篇文章主要介绍了Swift - 多行文本输入框(UITextView)的用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1,多行文本控件的创建
1
2
3
4
let textview= UITextView (frame: CGRectMake (10,100,200,100))
textview.layer.borderWidth=1 //边框粗细
textview.layer.borderColor= UIColor .grayColor(). CGColor //边框颜色
self .view.addSubview(textview)

2,是否可编辑
1
textview.editable= false

3,内容是否可选
textview.selectable=

4,属性font设置字体,textColor设置字体颜色,textAlignment设置对齐方式
5,给文字中的电话号码和网址自动链接
1
2
3
4
textview.dataDetectorTypes = UIDataDetectorTypes . None //都不加链接
PhoneNumber //只有电话加链接
Link //只有网址加链接
All //电话和网址都加

6,自定义选择内容后的菜单 我们在看新闻或小说的时候,常常在点选文字后会弹出菜单进行选择,复制等操作。我们可以在这个菜单添加一些其他内容,如加上邮件”“微信”等按钮选项

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import UIKit
class ViewController : UIViewController {
override func viewDidLoad() {
super .viewDidLoad()
//边框粗细
//边框颜色
.view.addSubview(textview)
mail = UIMenuItem (title: "邮件" ,action: "onMail" )
weixin = "微信" "onWeiXin" )
menu = UIMenuController ()
menu.menuItems = [mail,weixin]
}
onMail(){
print ( "mail" )
}
onWeiXin(){
"weixin" )
}
didReceiveMemoryWarning() {
.didReceiveMemoryWarning()
}
}

原文出自: www.hangge.com 转载请保留原文链接 http://www.hangge.com/blog/cache/detail_531.html 原文链接:https://www.f2er.com/swift/324914.html

猜你在找的Swift相关文章