UITextView 的一些用途

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 100, 275, 100)];
    textView.backgroundColor = [UIColor grayColor];
    NSString *str = @"编辑文本时没那么重要,但如果要18672136121 但如果要以好看易读的方式展现文本时,这就相当重要, www.baidu.com, [email protected] [email protected]";
        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;

你可能感兴趣的:(UITextView 的一些用途)