UIKit 框架之UITextView
//
// ViewController.m
// UItextView
//
// Created by City--Online on 15/5/22.
// Copyright (c) 2015年 XQB. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UITextViewDelegate>
@property(nonatomic,strong) UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_textView=[[UITextView alloc]initWithFrame:CGRectMake(10, 100, 200, 100)];
//设置代理
_textView.delegate=self;
//设置文本内容
_textView.text=@"text啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈啊哈ahahahhahahahah哈哈哈哈哈哈哈哈哈哈哈哈哈哈text啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈啊哈ahahahhahahahah哈哈哈哈哈哈哈哈哈哈哈哈哈哈";
//设置字体
_textView.font=[UIFont systemFontOfSize:20];
//设置字体颜色
_textView.textColor=[UIColor redColor];
//设置文本对齐方式
_textView.textAlignment=NSTextAlignmentRight;
//设置选择的文本
_textView.selectedRange=NSMakeRange(0, _textView.text.length-2);
//设置可编辑
_textView.editable=YES;
//设置可选择状态
_textView.selectable=YES;
//可以设定使电话号码、网址、电子邮件和符合格式的日期等文字变为链接文字
_textView.dataDetectorTypes=UIDataDetectorTypePhoneNumber;
//设置文本是否可编辑
_textView.allowsEditingTextAttributes=YES;
//设置文本属性样式
NSMutableAttributedString *attributedString=[[NSMutableAttributedString alloc]initWithString:_textView.text];
[attributedString addAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:[UIFont systemFontOfSize:20]} range:NSMakeRange(0, _textView.text.length)];
_textView.attributedText=attributedString;
//设置属性字典
_textView.typingAttributes=@{NSFontAttributeName:[UIFont systemFontOfSize:30]};
//设置边框宽度
_textView.layer.borderWidth=3.0;
//设置滚动时反弹
_textView.bounces=NO;
//设置弹出视图
_textView.inputView=nil;
//设置辅助视图
_textView.inputAccessoryView=nil;
//设置当插入值时是否清空原有内容 selectedRange范围的
_textView.clearsOnInsertion=YES;
//设置链接样式
_textView.linkTextAttributes=@{NSForegroundColorAttributeName:[UIColor redColor]};
[self.view addSubview:_textView];
//滚动到指定的Range
// [_textView scrollRangeToVisible:NSMakeRange(_textView.text.length-10, _textView.text.length)];
// _textView.selectedRange=NSMakeRange(_textView.text.length-10, _textView.text.length);
}
// 在TextView获取焦点之前执行
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(@"textViewShouldBeginEditing");
return YES;
}
//在TextView离开焦点之后执行
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
NSLog(@"textViewShouldEndEditing");
return YES;
}
//在TextView开始编辑时获得焦点
- (void)textViewDidBeginEditing:(UITextView *)textView
{
NSLog(@"textViewDidBeginEditing");
}
//在TextView结束编辑时
- (void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(@"textViewDidEndEditing");
}
//每次用户通过键盘输入字符时,在字符显示在text view之 前,textView:shouldChangeCharactersInRange:replacementString方法会被调用。这个方法中可以 方便的定位测试用户输入的字符,并且限制用户输入特定的字符
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSCharacterSet *doneButtonCharacterSet = [NSCharacterSet newlineCharacterSet];
NSRange replacementTextRange = [text rangeOfCharacterFromSet:doneButtonCharacterSet];
NSUInteger location = replacementTextRange.location;
if (textView.text.length + text.length > 140){
if (location != NSNotFound){
[textView resignFirstResponder];
}
return NO;
}
else if (location != NSNotFound){
[textView resignFirstResponder];
return NO;
}
return YES;
}
- (void)textViewDidChange:(UITextView *)textView
{
NSLog(@"textViewDidChange");
}
//光标位置改变
- (void)textViewDidChangeSelection:(UITextView *)textView
{
NSLog(@"textViewDidChangeSelection");
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
NSLog(@"shouldInteractWithURL");
return YES;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange
{
NSLog(@"shouldInteractWithTextAttachment");
return YES;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
[super touchesBegan:touches withEvent:event];
NSLog(@"touchesBegan:withEvent");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
UITextView有几个IOS7的属性没写

UIKit 框架之UITextView的更多相关文章
- UIKit框架使用总结--看看你掌握了多少
一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...
- Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)
原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...
- UIKit框架
在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...
- iOS学习32之UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 基础框架Fundation和UIkit框架的定义和使用
Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...
- iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。
转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架
Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...
- UIKit 框架之UIView二
下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...
随机推荐
- web中浏览PDF文件
1.在web中浏览pdf文件. 2.支持大多数主流浏览器,包括IE8 3.参考网址: https://pdfobject.com/ http://mozilla.github.io/pdf.js/ & ...
- 基于C#语言MVC框架Aspose.Cells控件导出Excel表数据
控件bin文件下载地址:https://download.csdn.net/download/u012949335/10610726 @{ ViewBag.Title = "xx" ...
- sp2010 升级sp2013 用户无法打开网站
Add-PSSnapin microsoft.sharepoint.powershell $WebAppName = "http://wtcsps99:82/" $wa = get ...
- C#使用PriorityQueue
#pragma once #include<cliext/queue> #include<cliext/vector> using namespace cliext; usin ...
- C++中vector的使用
在c++中,vector是一个十分有用的容器. 作用:它能够像容器一样存放各种类型的对象,简单地说,vector是一个能够存放任意类型的动态数组,能够增加和压缩数据. vector在C++标准模板库中 ...
- FunDA(6)- Reactive Streams:Play with Iteratees、Enumerator and Enumeratees
在上一节我们介绍了Iteratee.它的功能是消耗从一些数据源推送过来的数据元素,不同的数据消耗方式代表了不同功能的Iteratee.所谓的数据源就是我们这节要讨论的Enumerator.Enumer ...
- Python中线程与互斥锁
了解之前我们先了解一下什么是多任务? 概念: 几个不同的事件在同时运行就是多任务, 这样的话, 我们有牵扯到了真的多任务, 假的多任务; 并行: 真的多任务, 通过电脑的核数来确定 并发: 假的多任务 ...
- Centos7下安装zabbix 3.0.19
参考网站: https://www.cnblogs.com/xiewenming/p/7732144.html https://www.cnblogs.com/clsn/p/7885990.html ...
- 03——Solr学习之Solr的使用(不会用)
1.先放上次在linux搭建成功的solr管理UI界面 2.有个很蛋疼的问题我就要吐槽一下了 由于没接触过solr这玩意,在百度上一顿操作搜索怎么用,怎么导入数据,建索引库什么的,看了一大片别人的博客 ...
- Linux文件目录管理
Linux文件目录管理 文件的路径 路径: . 表示当此层目录 .. 表示上一层目录 - 代表前一个工作目录 ~ 代表"目前用户身份"所在的文件夹 ~account 代表accou ...