标签:
// // 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"; _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:15]}; [self.view addSubview:_textView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
标签:
原文地址:http://www.cnblogs.com/cuiyw/p/4523019.html