加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 01:28:39 所属栏目:百科 来源:网络整理
导读: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,多行文本控件的创建
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读