swift UITextView

/* swift 3.0    UITextField的使用  */

        

        /* 1. 创建UITextField */

        let textView = UITextView.init(frame: CGRect.init(x: 0, y: 0, width: 200, height: 200))

        textView.center = view.center

        textView.layer.borderWidth = 1 /* 边框线 */

        textView.layer.borderColor = UIColor.init(colorLiteralRed: 200.0/255.0, green: 200/255.0, blue: 200/255.0, alpha: 1).cgColor

        

        view.addSubview(textView)

        

        textView.text = "114dd东方饭店的地方 13135211076  http://www.baidu.com 飞飞飞哥哥哥哥哥哥给发个"

        

        

        

        /* 2. 是否可以编辑  */

        textView.isEditable = false  /* 只能禁止输入,无法禁止其选中,全选*/

        

        

        

        

        /* 3. 内容是否可选 */

    //    textView.isSelectable = false /* 不仅禁止输入,而且禁止选中,全选 */

        

        

        

        /* 4. 设置字体, 设置字体颜色, 设置对齐方式 */

        textView.font = UIFont.systemFont(ofSize: 20)

        textView.textColor = UIColor.green

        textView.textAlignment = .center

        

        

        

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

            

            使用这个属性时,  textView.isSelectable 必须为true

            发现实际上并没有啥用处,一般采用富文本处理

         */

        textView.dataDetectorTypes = []  /*  什么都不加,默认清醒 */

        textView.dataDetectorTypes = .phoneNumber  /* 电话号码增加链接 */

        textView.dataDetectorTypes = .link  /* 网址增加链接 */

        textView.dataDetectorTypes = .all  /*  电话号码和网址都增加链接 */

        

        

        

        /* 6. 长按textView时弹出的 菜单栏  1)增加选项  2)增加选项对应事件 */

        let  menu = UIMenuController()

        let  mail = UIMenuItem.init(title: "邮件", action: #selector(onMail))

        let  weixin = UIMenuItem.init(title: "微信", action: #selector(onMail))

        menu.menuItems = [mail , weixin]

        

        

        /* 7. 调整行间距   富文本属性NSParagraphStyleAttributeName

            

                不过文本无法再以居中形式显示

         */

        let paragraphStyle =  NSMutableParagraphStyle()

        paragraphStyle.lineSpacing = 20

        

        textView.attributedText = NSAttributedString.init(string: "1111ffgks的房间看房费加扣扣罚款发货改革开放的弟弟好看的好的话的健康的方法恢复", attributes: [NSParagraphStyleAttributeName:paragraphStyle])

        

        

        

        

        /* 8. textView中的placeHolder问题 

         

            textView中没有placeHolder,那么如何模拟一个了?

            方法:

             (1)textView1中添加一个textView2,且设置颜色为灰色;

             (2)再给textView1添加代理,当text""时,show textView2,以及textView2中的文本; text不为空时,那么 hidden textView2;

         */

        

        

        

        

        

        

        

        /* 9. textView中左右间距调整问题 

         

            textField中可以使用leftView,rightView来增加左右的间距;那么如何实现textView的左右两边间距?

            方法:

             (1)textView1中添加textView2;

             (2)那么用textView1显示边框,而textView2不显示边框,且输入时就再textView2中显示就行了;

         */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值