UITextView -- 基础备忘
UITextView
这篇文章只涉及到基本的使用,日后会写一些关于结合TextKit的备忘
基本属性
let screenSize = UIScreen.mainScreen().bounds.size
let textView = UITextView(frame: CGRectMake(0, 20, screenSize.width, 200))
textView.font = UIFont.systemFontOfSize(20)
textView.selectable = false
textView.scrollEnabled = true
textView.editable = true
textView.textColor = UIColor.whiteColor()
textView.backgroundColor = UIColor.blackColor()
textView.text = "The UITextView class implements the behavior for a scrollable, multiline text region. The class supports the display of text using custom style information and also supports text editing. You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document."
textView.textAlignment = .Center
textView.textContainerInset = UIEdgeInsetsMake(60, 0, 0, 0)
textView.keyboardType = .Default
textView.returnKeyType = .Default
view.addSubview(textView) self.textView = textView
- font:字体
- selectable:是否可以选中。
- scrollEnabled:是否可以滚动。
- editable:是否可以编辑。
- textColor:文字颜色。
- backgroundColor:背景色。
- text:要显示的文字。
- textAlignment:文字排版样式。
- textContainerInset:文字的距离textview的内边距。
- keyboardType:键盘样式。
- returnKeyType:return键的样式。
监听通知
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.textViewDidBeginEdit(_:)), name: UITextViewTextDidBeginEditingNotification, object: textView)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.textViewTextDidChange(_:)), name: UITextViewTextDidChangeNotification, object: textView)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.textViewDidEndEdit(_:)), name: UITextViewTextDidEndEditingNotification, object: textView) func textViewDidBeginEdit(notification: NSNotification) {
print(notification.name)
} func textViewTextDidChange(notification: NSNotification) {
print(notification.object)
} func textViewDidEndEdit(notification: NSNotification) {
print(notification.name)
} deinit{
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, object: textView)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidEndEditingNotification, object: textView)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidBeginEditingNotification, object: textView)
}
代理方法
extension ViewController: UITextViewDelegate {
// 是否应该开始编辑
func textViewShouldBeginEditing(textView: UITextView) -> Bool {
print("textViewShouldBeginEditing")
return true
}
// 是否应该停止编辑
func textViewShouldEndEditing(textView: UITextView) -> Bool {
print("textViewShouldEndEditing")
return true
}
// 文字视图已经开始编辑
func textViewDidBeginEditing(textView: UITextView) {
print("textViewDidBeginEditing")
}
// 文字视图已经停止编辑
func textViewDidEndEditing(textView: UITextView) {
print("textViewDidEndEditing")
}
// 文字视图是否允许替换文字,每当有文字要被输入或删除都会先调用这个方法
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
if text == "\n" {
textView.resignFirstResponder()
return false
}
return true
}
// 文字视图文字已经被替换
func textViewDidChange(textView: UITextView) {
print("textViewDidChange")
}
// 每当有一组文字被选中或删除输入、放大镜的移动,都会调用此方法
func textViewDidChangeSelection(textView: UITextView) {
print("textViewDidChangeSelection")
}
UITextView -- 基础备忘的更多相关文章
- scala基础备忘
声明一个变量 声明一个常量 显式指定类型 定义一个main函数 package org.admln.scala class HelloScala { } object HelloScala { def ...
- Java Socket基础[备忘]
1.服务端----Server.java import javax.swing.*; import java.io.*; import java.net.*; import java.awt.*; i ...
- ajax基础------备忘
1:register.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- javaweb基础备忘
Request对象的主要方法有哪些 setAttribute(String name,Object):设置名字为name的request 的参数值 getAttribute(String name): ...
- Linux基础之常用基本命令备忘
Linux基础之常用基本命令备忘 PWD 查询当前所在Linux上的位置 / 根目录 CD(change directory)切换目录 语法 CD /(注意添加空格) LS ...
- Nmap备忘单:从探索到漏洞利用(Part 4)
这是我们的Nmap备忘单的第四部分(Part 1. Part 2. Part 3).本文中我们将讨论更多东西关于扫描防火墙,IDS / IPS 逃逸,Web服务器渗透测试等.在此之前,我们应该了解一下 ...
- HTML5终极备忘大全
二.文字备忘之标签 HTML5中新增的标签 <article> 定义文章 <aside> 定义页面内容旁边的内容 <audio> 定义声音内容 <canvas ...
- [转] HTML5终极备忘大全(图片版+文字版)---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1544 一.前言兼图片 ...
- Table view 备忘
Table view 备忘 本篇会以备忘为主,主要是一些基础的代理方法和数据源方法具体的优化好点子会后续跟上. Table view的数据源方法 必须实现的数据源方法 // 返回每一行的cell,可以 ...
随机推荐
- [React] React Fundamentals: Mixins
Mixins will allow you to apply behaviors to multiple React components. Components are the best way t ...
- “:Choose a destination with a supported architecture in order to run on this device.”
我在编译从GitHub上clone下来的<TweeJump>时,出现如下错误:":Choose a destination with a supported architectu ...
- 打造强大的BaseModel(2):让Model实现自动映射,将字典转化成Model
打造强大的BaseModel(1):让Model自我描述 这篇文章将讲述Model一项更高级也最常用的功能,让Model实现自动映射–将字典转化成Model(所有代码全由Swift实现) 将JSON转 ...
- Android Studio快捷键指南(本文持续更新)
这是我在使用Android Studio过程中接触到的一些快捷键,和大家分享,后面会继续完善此文,也欢迎大家踊跃补充,一起完善. 快捷键 删除并剪贴行:Ctrl+X 复制一行:Ctrl+D 代码格式整 ...
- 使用ViewState[""]传递Hashtable的值
//首先定义Hashtable myHach = new Hashtable(); //添加键值到Hashtable中myHash.Add("ServiceType1", &quo ...
- ibatis配置xml文件中CDATA的用法
ibatis作为一种半自动化的OR Mapping工具,其灵活性日益体现出来,越来越多的人都倾向于在项目中使用.由于Sql中经常有与xml规范相冲突的字符对xml映射文件的合法性造成影响.许多人都知道 ...
- 从入行到现在(.net)
每次写东西都不知道怎么去开头.因为一想到要写东西.脑子里面浮现出来的开头就太多. 进园子很久从开始只是关注别人讲的技术,别人讲的基础,到现在更多的去看大家的随笔和新闻.这两年我从零基础的外行人逐渐进入 ...
- web.config详解(配置文件节点说明)
转载:http://www.zzzj.com/html/20081110/67614.html web.config文件是一个XML文件,它的根结点是<configuration>,在&l ...
- C#微信公众号开发 -- (五)自定义菜单创建
公众号中,底部都是有自己定义的功能按钮,通过点击某个按钮来实现指定的业务逻辑操作. 下面就来说说这些按钮是怎样放到微信公众平台的,还是先来看看微信的官方解释: 请注意: 1.自定义菜单最多包括3个一级 ...
- com.android.builder.packaging.DuplicateFile
解决方法: packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' ...