美文网首页
5. UITextView

5. UITextView

作者: LucXion | 来源:发表于2017-09-13 16:09 被阅读0次

    标签:输入前清空、行间距设置、自定义键盘

    • 常用方法

    1.修改行间距,执行如下代码

    //    textview 改变字体的行间距     
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];     
    paragraphStyle.lineSpacing = 10;
    // 字体的行间距     
    NSDictionary *attributes = @{
      NSFontAttributeName:[UIFont systemFontOfSize:15],
      NSParagraphStyleAttributeName:paragraphStyle           
    };
    textView.attributedText = [[NSAttributedString alloc] initWithString:@"输入你的内容" attributes:attributes];
    

    2. font
    设置textView中文字的字体

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

    3.textAlignment:设置textView的文本的排列方法

    // textView中的文本排列,默认靠左
    _textView.textAlignment = NSTextAlignmentCenter; 
    
    1.png

    4.editable
    设置textView是否可被输入

    5.attributedText

    // 可以方便将文本插入到UITextView中。
    _textView.attributedText = [[NSAttributedString alloc]initWithString:@"attributedText__-abc"]; 
    

    6.inputView
    设置从底部弹出的视图

    // 弹出视图,默认为键盘
    _textView.inputView = [[UIDatePicker alloc]init]; 
    
    6.png

    7.inputAccessoryView
    设置弹出视图上方的辅助视图

    // 弹出视图上方的辅助视图
    _textView.inputAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    
    7.png

    8.clearsOnInsertion
    设置textView获得焦点,在用户使用虚拟键盘进行输入时,清除之前的文本

    // clearsOnInsertion,默认为NO
    _textView.clearsOnInsertion = YES; 
    

    相关文章

      网友评论

          本文标题:5. UITextView

          本文链接:https://www.haomeiwen.com/subject/lbflsxtx.html