iOS开发之基础视图——UITextView

     多行文本控件(UITextView)继承了UIScrollView:UIView控件,因此它默认带有滚动条。

      UITextField  和  UITextView 的区别

      UITextField

           能输入 行数据

      UITextView

           能输入 行数据

      UITextView没有继承父类,绑定事件操作不方便

      UITextView 继承了UIScrollView ,支持垂直和水平的滚动条 



//
//  ViewController.m
//  UITextViewDemo
//
//  Created by Apple on 16/5/11.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

//声明一个全局的UITextView文本域
UITextView* textView;


- (void)viewDidLoad {
    [super viewDidLoad];
    //  初始化上述声明的UITextView文本域
    textView = [[UITextView alloc] initWithFrame:CGRectMake(50,300,200,100)];
    
    // 设置它的背景颜色
    textView.backgroundColor = [UIColor grayColor];
    // 设置textview里面的字体颜色
    textView.textColor = [UIColor blackColor];
    // 设置默认显示的内容
    textView.text = @"请输入详细信息";
    //设置是否允许开启滚动
    textView.scrollEnabled = YES;
    //开启是否显示边界
    textView.showsHorizontalScrollIndicator = YES;
    //设置超出边界到时候是否有弹簧效果(默认YES)
    textView.bounces = YES;
    //键盘类型
    textView.keyboardType = UIKeyboardTypeDefault;
    //返回键的类型
    textView.returnKeyType = UIReturnKeyDefault;
    // 添加到当前view
    [self.view addSubview:textView];
}

   //当触碰到非文本域的空白处,关闭键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)UIEvent{
    [textView resignFirstResponder];
}

@end

     效果图如下:

   

   

    

你可能感兴趣的:(ios开发,UITextView)