1,多行文本控件的创建

1
2
3
4
var 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,内容是否可选

1
textview.selectable=false

4,属性font设置字体,textColor设置字体颜色,textAlignment设置对齐方式

5,给文字中的电话号码和网址自动加链接

1
2
3
4
textview.dataDetectorTypes = UIDataDetectorTypes.None //都不加链接
textview.dataDetectorTypes = UIDataDetectorTypes.PhoneNumber //只有电话加链接
textview.dataDetectorTypes = UIDataDetectorTypes.Link //只有网址加链接
textview.dataDetectorTypes = UIDataDetectorTypes.All //电话和网址都加

6,自定义选择内容后的菜单

我们在看新闻或小说的时候,常常在点选文字后会弹出菜单进行选择,复制等操作。我们可以在这个菜单上添加一些其他内容,如加上“邮件”“微信”等按钮选项
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import UIKit
 
class ViewController: UIViewController {
 
    override func viewDidLoad() {
        super.viewDidLoad()
         
        var mail = UIMenuItem(title: "邮件", action: "onMail")
        var weixin = UIMenuItem(title: "微信", action: "onWeiXin")
        var menu = UIMenuController()
        menu.menuItems = NSArray(array: [mail,weixin])       
    }
     
    func onMail(){
        println("mail")
    }
     
    func onWeiXin(){
        println("weixin")
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

Swift - 多行文本输入框(UITextView)的用法的更多相关文章

  1. Swift - 多行文本输入框(UITextView)

    1,多行文本控件的创建 1 2 3 4 let textview = UITextView(frame:CGRect(x:10, y:100, width:200, height:100)) text ...

  2. swift - UITextView的用法

    1,多行文本控件的创建 textView.frame = CGRect(x:50,y:180,width:self.view.bounds.size.width - 100,height:50) te ...

  3. Swift - 搜索条(UISearchBar)的用法

    1,搜索条Options属性还可设置如下功能样式: Shows Search Results Button:勾选后,搜索框右边显示一个圆形向下的按钮,单击会发送特殊事件. Shows Bookmark ...

  4. Swift - 告警框(UIAlertView)的用法

    1,下面代码创建并弹出一个告警框,并带有“取消”“确定”两个按钮 (注:自IOS8起,建议使用UIAlertController) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...

  5. Swift - 键盘弹起,遮挡输入框

    extension LoginViewController:UITextFieldDelegate { func textFieldShouldReturn(textField: UITextFiel ...

  6. Swift - 进度条(UIProgressView)的用法

    1,创建进度条 1 2 3 4 var progressView=UIProgressView(progressViewStyle:UIProgressViewStyle.Default) progr ...

  7. Swift - 工具条(UIToolbar)的用法

    1,UIBarButtonItem是工具条按钮,有如下5种init初始化方法: (1)初始化为普通图片按钮 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  8. Swift - 加速传感器(CoreMotion)的用法,小球加速运动并反弹样例

    1,加速传感器可以监听到x,y,z三个方向的加速度,使用步骤如下: (1)实例化CMMotionManager类 (2)向CMMotionManager的accelerometerUpdateInte ...

  9. Swift - 滚动视图(UIScrollView)的用法

    1,当图片尺寸超过屏幕时,使用UIScrollView可以实现滚动条视图,即手指触摸滚动屏幕方便浏览整个页面. 1 2 3 4 5 6 var scrollView=UIScrollView() sc ...

随机推荐

  1. MySQL新建用户,授权,删除用户,修改密码等命令

    首先要声明一下:一般情况下,修改MySQL密码,授权,是需要有mysql里的root权限的. 注:本操作是在WIN命令提示符下,phpMyAdmin同样适用.     用户:phplamp   用户数 ...

  2. Ext.net中常用的三种交互方式

    http://www.ext.net.cn/forum.php?mod=viewthread&tid=10433

  3. [转]SELinux管理与配置

    原文链接:http://blog.csdn.net/huangbiao86/article/details/6641893 1.1 SElinux概述 SELinux(Security-Enhance ...

  4. AES加密时抛出java.security.InvalidKeyException: Illegal key size or def

    原文:AES加密时抛出java.security.InvalidKeyException: Illegal key size or def 使用AES加密时,当密钥大于128时,代码会抛出 java. ...

  5. lokijs

    http://lokijs.org/#/ 500,000+ 1.1M ops/s. A fast, in-memory document-oriented datastore for node.js, ...

  6. <脱机手写汉字识别若干关键技术研究>

    脱机手写汉字识别若干关键技术研究 对于大字符集识别问题,一般采用模板匹配的算法,主要是因为该算法比较简单,识别速度快.但直接的模板匹配算法往往无法满足实际应用中对识别精度的需求.为此任俊玲编著的< ...

  7. poj 3767 I Wanna Go Home

    题意:n个点(从1-n编号) m条边 下面m行 u v dis 表示双向边u v的距离 n个点表示 每个点被势力1或2占据 这里保证1 城市由势力1占据,2城市由势力2占据 思路: 求2遍spfa() ...

  8. 【COCOS2D-HTML5 开发之三】演示样例项目附源代码及执行的GIF效果图

    本站文章均为李华明Himi原创,转载务必在明显处注明:(作者新浪微博:@李华明Himi) 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/cocos2d- ...

  9. WCF技术剖析之五:利用ASP.NET兼容模式创建支持会话(Session)的WCF服务

    原文:WCF技术剖析之五:利用ASP.NET兼容模式创建支持会话(Session)的WCF服务 在<基于IIS的WCF服务寄宿(Hosting)实现揭秘>中,我们谈到在采用基于IIS(或者 ...

  10. ASP.NET - 后台获取按钮绑定的值CommandArgument

    <asp:LinkButton runat="server" ID="resumelbtn" CommandArgument='<%# Eval(& ...