zoukankan      html  css  js  c++  java
  • iOS UI-文本视图(UITextView)

     1 #import "ViewController.h"
     2 
     3 @interface ViewController ()<UITextViewDelegate>
     4 
     5 @property (strong, nonatomic) UITextView *textView;
     6 
     7 @end
     8 
     9 @implementation ViewController
    10 
    11 @synthesize textView;
    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
  • 相关阅读:
    XStream和Dom4j的区别
    tomcat 性能优化(内存优化 线程优化)
    安装tomcat
    python 全栈开发,Day10(动态参数,命名空间,作用域,函数嵌套)
    python 全栈开发,Day9(函数的初始,返回值,传参,三元运算)
    python 全栈开发,Day8(文件操作)
    python 全栈开发,Day7(元组转换,列表以及字典的坑,集合,关系测试,深浅copy,编码补充)
    python 全栈开发,Day6(is,小数据池,编码转换)
    python 全栈开发,Day5(字典,增删改查,其他操作方法)
    python 全栈开发,Day4(列表切片,增删改查,常用操作方法,元组,range,join)
  • 原文地址:https://www.cnblogs.com/oc-bowen/p/5091959.html
Copyright © 2011-2022 走看看