//
//  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的更多相关文章

  1. UIKit框架使用总结--看看你掌握了多少

    一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...

  2. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

  3. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  4. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  5. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  6. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  7. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  8. 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架

    Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...

  9. UIKit 框架之UIView二

    下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...

随机推荐

  1. Django:上传文件或者图片时request.FILES的值为空

    在form表单中加上属性 enctype="multipart/form-data"

  2. Global.asax和HttpModule的执行顺序

    Application_Start-->用户自定义的HttpModule-->Application_BeginRequest   (注册->调用) 看到Init方法(在用户自定义的 ...

  3. [转载]将json字符串转换成json对象

    例如: JSON字符串: var str1 = '{ "name": "cxh", "sex": "man" }'; J ...

  4. 显式等待-----Selenium快速入门(十)

    上一篇说了元素定位过程中的隐式等待,今天我们来探讨一下显示等待.显式等待,其实就是在使用WebDriverWait这个对象,进行等待.显式等待对比隐式等待,多了一些人性化的设置,可以说是更细化的隐式等 ...

  5. js图片自适应尺寸居中函数处理

    /* | autoSerializePicture.js 自适应格式化图片 | auther : baichaohua/2017-09-21 +---------------------------- ...

  6. 一个Form表单多个Submit提交按钮!实现提交不同的参数!

    给 submit 的按钮加onclick 方法来自定义预处理参数,比如<script type="text/javascript">function submitFun ...

  7. LinkedBlockingQueue源码解析(2)

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 3.3.public void put(E e) throws InterruptedException 原 ...

  8. FFmpeg编写的代码

    //初始化解封装    av_register_all();    avformat_network_init();    avcodec_register_all();    //封装文件的上下文  ...

  9. Python 面向对象编程的一些特征 及 单例模式的实现, 父类方法的调用(python2/python3)

    一.面向对象编程几个特征(封装, 继承,多态) 1.封装:类里面封装函数和变量, 在将类进行实例化成实例对象时进行传参, 从而生成不同的实例对象,增加代码的复用. 2.继承:子类可以继承父类的方法和属 ...

  10. 二叉堆的实现(数组)——c++

    二叉堆的介绍 二叉堆是完全二元树或者是近似完全二元树,按照数据的排列方式可以分为两种:最大堆和最小堆.最大堆:父结点的键值总是大于或等于任何一个子节点的键值:最小堆:父结点的键值总是小于或等于任何一个 ...