码迷,mamicode.com
首页 > 其他好文 > 详细

UIKit 框架之UITextView

时间:2015-05-22 18:50:36      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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

 

UIKit 框架之UITextView

标签:

原文地址:http://www.cnblogs.com/cuiyw/p/4523019.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!