zoukankan      html  css  js  c++  java
  • UITextView

    1、创建 UITextView 控件

    UITextView *txt = [[UITextView alloc] init];
    

    2、text:设置 textView 中文文本

    txt.text = @"My name is Sarah,What are your name ? ";
    

    3、font:设置 textView 中文字的字体

    txt.font = [UIFont fontWithName:@"Arial" size:35];
    // 或者可以如下设置
    txt.font = [UIFont systemFontOfSize:35];
    

    4、textColor:设置 textView 中文字颜色

    // 设置 textView中文字的颜色
    txt.textColor = [UIColor whiteColor];
    

    5、textAlignment:设置textView的文本的排列方式

    // 设置对齐方式:居中对齐(默认左对齐)
    txt.textAlignment = NSTextAlignmentCenter;
    

    6、backgroundColor:设置 textView的背景颜色

    txt.backgroundColor = [UIColor grayColor];
    

    效果图如下:

    7、delegate:设置代理

    txt.delegate = self;
    

    8、editable:设置文本是否可编辑(默认是 YES可编辑状态)

    txt.editable = NO;
    

    9、attributedText:设置默认插入 textView 的文字

    // 1.attributedText可更改 textView 内容的文本内容
    self.txt.attributedText = [[NSAttributedString alloc] initWithString:@"SleepingSun - 晒太阳的仙人掌"];
        
    // 2.在更改文本内容的同时,可以设置文本字体(大小,颜色等)
    // 2.1.设置字体大小
    NSDictionary *textDic = @{NSFontAttributeName :[UIFont systemFontOfSize:30]};
    // 2.2.把文本内容和字体字典传值给 attributedText 属性
    self.txt.attributedText = [[NSAttributedString alloc] initWithString:@"雪花飞扬,那是天使撕碎的纸张." attributes:textDic];
    

    效果图

    10、inputVIew:设置从底部弹出的视图

    self.txt.inputView = [[UIDatePicker alloc] init];
    

    效果图

    11、inputAccessoryView:设置弹出视图上方的辅助视图

    self.txt.inputAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd];
    

    效果图

    12、clearsOnInsertion:设置textView获得焦点,在用户使用虚拟键盘进行输入时,可对之前文本进行剪切,拷贝,分享等操作

     // clearsOnInsertion,默认为NO
     self.txt.clearsOnInsertion = YES;
    

    效果图

  • 相关阅读:
    array_keys
    strval
    is_numeric
    php static延迟静态绑定
    page39 类的访问权限控制
    page34类的继承
    被遗忘在角落的类型检查函数
    2.2.5重写静态变量
    2.2.3使用parent作用域
    16个最棒的WordPress博客写作发布工具【博主桌面工具】
  • 原文地址:https://www.cnblogs.com/sleepingSun/p/5301011.html
Copyright © 2011-2022 走看看