您的位置:首页 > 产品设计 > UI/UE

UITextView 的一些用途

2015-11-26 12:41 411 查看
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 100, 275, 100)];
textView.backgroundColor = [UIColor grayColor];
NSString *str = @"编辑文本时没那么重要,但如果要18672136121 但如果要以好看易读的方式展现文本时,这就相当重要, www.baidu.com, 459880251@qq.com zhz459880251@163.com";
NSMutableParagraphStyle *paraStyle01 = [[NSMutableParagraphStyle alloc] init];
//每行结尾 英文断点
paraStyle01.hyphenationFactor = 0.3;
NSDictionary *attrDict01 = @{
NSParagraphStyleAttributeName: paraStyle01,
NSFontAttributeName: [UIFont systemFontOfSize: 15] };
textView.attributedText = [[NSAttributedString alloc] initWithString: str  attributes: attrDict01];

textView.text = str;

//设置不能编辑状态, 才能开启dataDetectorTypes 属性
textView.editable = NO;
textView.dataDetectorTypes = UIDataDetectorTypeAll;

textView.delegate = self;
[self.view addSubview:textView];

----------------------------------------------
// 几种常用的代理方法
//将要开始编辑
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;

//将要结束编辑
- (BOOL)textViewShouldEndEditing:(UITextView *)textView;

//开始编辑
- (void)textViewDidBeginEditing:(UITextView *)textView;

//结束编辑
- (void)textViewDidEndEditing:(UITextView *)textView;

//内容将要发生改变编辑
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;

//内容发生改变编辑
- (void)textViewDidChange:(UITextView *)textView;

//焦点发生改变
- (void)textViewDidChangeSelection:(UITextView *)textView;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: