UI- UITextView

//  ViewController.m

//  fiedl

//  Created by cqy on 15/11/16.

//  Copyright (c) 2015年 cqy. All rights reserved.

#import "ViewController.h"

 

@interface ViewController ()<UITextViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    

    

    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 70, 80, 30)];

    textView.backgroundColor = [UIColor greenColor];//设置背景颜色

    textView.editable = YES; //是否允许编辑内容,默认为“YES”

    textView.scrollEnabled =  YES; //当文字超过视图的边框时是否允许向下滑动,默认为“YES”

    textView.bounces = YES;

    

   textView.font = [UIFont fontWithName:@"Arial" size:21];//设置字体名字和字体大小;

    textView.returnKeyType = UIReturnKeyRoute;//return键的类型

    textView.keyboardType =   UIKeyboardTypeURL;//键盘类型

    textView.textAlignment =NSTextAlignmentLeft;//文本显示格式的位置,默认为居左

    textView.layer.borderColor = [UIColor blackColor].CGColor;

    textView.layer.borderWidth = 3;

    textView.layer.cornerRadius = 10;

    textView.layer.masksToBounds = YES;

    textView.delegate = self;//设置代理方法的实现类

    textView.text = @"你真美 ...";//设置显示的文本内容

    textView.returnKeyType =UIReturnKeyDone;

    [self.view addSubview:textView];

    

    

    

    

    // Do any additional setup after loading the view, typically from a nib.

}

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{

    //将要开始编辑

    NSLog(@"将要开始编辑...");

    return YES;

}

-(BOOL)textViewShouldEndEditing:(UITextView *)textView{

    //将要结束编辑

    NSLog(@"将要结束编辑...");

    return YES;

}

 

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    //内容将要发生改变编辑

    NSLog(@"--%@--",text);

    if([text isEqualToString:@"\n"]){

        [textView resignFirstResponder];

    }

    return YES;

}

-(void)textViewDidBeginEditing:(UITextView *)textView{

    //开始编辑

    NSLog(@"--->%@",textView.text);}

-(void)textViewDidChangeSelection:(UITextView *)textView{

    //结束编辑

    NSLog(@"结束编辑...");

}

 - (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

posted on 2015-11-16 20:02  清清杨  阅读(122)  评论(0编辑  收藏  举报

导航