iOS UI-文本视图(UITextView)

摘要:
1#import"ViewController.h"23@interfaceViewController()45@property(strong,nonatomic)UITextView*textView;67@end89@implementationViewController1011@synthesizetextView;1213-(void)viewD
1 #import "ViewController.h"
2 
3 @interface ViewController ()<UITextViewDelegate>
4 
5 @property (strong, nonatomic) UITextView *textView;
6 
7 @end
8 
9 @implementationViewController
10 
11 @synthesizetextView;
12 
13 - (void)viewDidLoad {
14 [super viewDidLoad];
15     //创建视图
16     UIView *bgView =[[UIView alloc] initWithFrame:self.view.frame];
17     bgView.backgroundColor =[UIColor lightGrayColor];
18 [self.view addSubview:bgView];
19     //创建点击手势
20     UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoard)];
21 [bgView addGestureRecognizer:tap];
22     
23     //初始化大小
24     self.textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 150, self.view.frame.size.width-100, 300)];
25     //字体颜色
26     self.textView.textColor =[UIColor blackColor];
27     //字体名称和大小
28     self.textView.font = [UIFont fontWithName:@"Arial" size:18.0];
29     //设置委托方法
30     self.textView.delegate =self;
31     //背景颜色
32     self.textView.backgroundColor =[UIColor whiteColor];
33     //内容
34     //self.textView.text = @"qwertyuyiopasdfghjklzxcvbnm";
35     //返回键类型
36     self.textView.returnKeyType =UIReturnKeyDefault;
37     //键盘类型
38     self.textView.keyboardType =UIKeyboardTypeNamePhonePad;
39     //是否可以拖动
40     self.textView.scrollEnabled =YES;
41     //禁止编辑
42     self.textView.editable =YES;
43     //自适应高度
44     self.textView.autoresizingMask =UIViewAutoresizingFlexibleHeight;
45     //加到整个页面中
46 [self.view addSubview:self.textView];
47 }
48 
49 - (void)closeKeyBoard
50 {
51 [self.textView resignFirstResponder];
52 }
53 - (void)textViewDidBeginEditing:(UITextView *)textView
54 {
55     [UIView beginAnimations:@"test"context:nil];
56     [UIView setAnimationDuration:0.3];
57     
58     CGRect rect =self.textView.frame;
59     rect.origin.y = rect.origin.y - 80;
60     self.textView.frame =rect;
61 [UIView commitAnimations];
62 }
63 
64 - (void)textViewDidEndEditing:(UITextView *)textView
65 {
66     [UIView beginAnimations:@"test"context:nil];
67     [UIView setAnimationDuration:0.3];
68     
69     CGRect rect =self.textView.frame;
70     rect.origin.y = rect.origin.y + 80;
71     self.textView.frame =rect;
72 [UIView commitAnimations];
73 }
74 
75 - (void)didReceiveMemoryWarning {
76 [super didReceiveMemoryWarning];
77     //Dispose of any resources that can be recreated.
78 }
79 
80 @end

免责声明:文章转载自《iOS UI-文本视图(UITextView)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SpringXML方式配置bean的集合注入:list,map,propertiesTP6框架--EasyAdmin学习笔记:Excel表单导入数据库下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

[ PyQt入门教程 ] Qt Designer工具的使用

Qt Designer是PyQt程序UI界面的实现工具,使用Qt Designer可以拖拽、点击完成GUI界面设计,并且设计完成的.ui程序可以转换成.py文件供python程序调用。本文主要通过用户登录需求描述Qt Designer工具开发界面的使用方法。 本文主要内容1、Qt Designer程序主界面窗口介绍。 2、Qt Designer程序实现界面...

GSAP JS基础教程--使用缓动函数

今天来了解一下缓动easeing函数。 开始,如果你还没有GSAP的类包,可以到GreenSock的官网去下载最新版本的类包,或者直接点击这里​来下载 学习之前,先来准备一下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/...

MFC画刷类CBrush使用实例 .

画刷类CBrush利用画笔可以画图形的边框,而用画刷就可以在图形内着色。大多数的GDI绘图函数既使用画笔又使用画刷,它们用画笔绘制各种图形的周边,而用画刷填充图形,因而可以用一种颜色和风格去设置画笔,而用另一种颜色和风格去设定画刷,通过一次函数调用就可以绘制出形状复杂的图形。画刷是由CBrush类管理的,创建画刷有两种方法:一种是调用构造函数,另一种是调用...

UITextView in iOS7 doesn&amp;amp;#39;t scroll

UITextView in iOS7 has been really weird. As you type and are entering the last line of your UITextView, the scroll view doesn't scroll to the bottom like it should and it cause...

[转]go语言中的接口

转,原文:  https://www.jianshu.com/p/82436645927b ------------------------------ 原文:https://medium.com/rungo/interfaces-in-go-ab1601159b3a 翻译:devabel 接口是golang中实现多态性的唯一好途径。 什么是接口? 我...

UIBezierPath精讲

前言 笔者在写本篇文章之前,也没有系统学习过贝塞尔曲线,只是曾经某一次的需求需要使用到,才临时百度看了一看而且使用最基本的功能。现在总算有时间停下来好好研究研究这个神奇而伟大的贝塞尔先生! 笔者在学习时,首先看了两遍UIBezierPath类头文件定义,熟悉了一下相关的属性和方法。 基础知识 使用UIBezierPath可以创建基于矢量的路径,此类是Cor...