UITextView的常用方法,属性

示例代码

// 初始化输入框并设置位置和大小
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 100, [UIScreen mainScreen].bounds.size.width - 20, 180)];
    // 设置预设文本
    textView.text = @"您的意见是我们前进的最大动力,谢谢!";
    // 设置文本字体
    textView.font = [UIFont fontWithName:@"Arial" size:16.5f];
    // 设置文本颜色
    textView.textColor = [UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1.0f];
    // 设置文本框背景颜色
    textView.backgroundColor = [UIColor whiteColor];
    // 设置文本对齐方式
    textView.textAlignment = NSTextAlignmentLeft;
    // 设置自动纠错方式
    textView.autocorrectionType = UITextAutocorrectionTypeNo;

    //外框
    textView.layer.borderColor = [UIColor redColor].CGColor;
    textView.layer.borderWidth = 1;
    textView.layer.cornerRadius =5;


    // 设置自动大写方式
    textView.autocapitalizationType = UITextAutocapitalizationTypeNone;

    // 自动大写方式有以下几种:
    //    enum {
    //        UITextAutocapitalizationTypeNone,           不自动大写
    //        UITextAutocapitalizationTypeWords,          单词首字母大写
    //        UITextAutocapitalizationTypeSentences,      句子的首字母大写
    //        UITextAutocapitalizationTypeAllCharacters,  所有字母都大写
    //    } UITextAutocapitalizationType;

    // 设置键盘的样式
    textView.keyboardType = UIKeyboardTypeDefault;

    // 键盘样式有以下几种:
    //    enum {
    //        UIKeyboardTypeDefault,                默认键盘,支持所有字符
    //        UIKeyboardTypeASCIICapable,           支持ASCII的默认键盘
    //        UIKeyboardTypeNumbersAndPunctuation,  标准电话键盘,支持+*#字符
    //        UIKeyboardTypeURL,                    只支持URL字符的URL键盘,支持.com按钮
    //        UIKeyboardTypeNumberPad,              数字键盘
    //        UIKeyboardTypePhonePad,               电话键盘
    //        UIKeyboardTypeNamePhonePad,           支持输入人名的电话键盘
    //        UIKeyboardTypeEmailAddress,           电子邮件键盘
    //        UIKeyboardTypeDecimalPad,             有数字和小数点的数字键盘
    //        UIKeyboardTypeTwitter,                优化的键盘,方便输入@、#字符
    //        UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
    //    } UIKeyboardType;

    // 设置return键样式
    textView.returnKeyType = UIReturnKeyDefault;

    // return键有以下几种样式:
    //    enum {
    //        UIReturnKeyDefault,        默认,灰色按钮,标有Return
    //        UIReturnKeyGo,             标有Go的蓝色按钮
    //        UIReturnKeyGoogle,         标有Google的蓝色按钮,用于搜索
    //        UIReturnKeyJoin,           标有Join的蓝色按钮
    //        UIReturnKeyNext,           标有Next的蓝色按钮
    //        UIReturnKeyRoute,          标有Route的蓝色按钮
    //        UIReturnKeySearch,         标有Search的蓝色按钮
    //        UIReturnKeySend,           标有Send的蓝色按钮
    //        UIReturnKeyYahoo,          标有Yahoo的蓝色按钮
    //        UIReturnKeyYahoo,          标有Yahoo的蓝色按钮
    //        UIReturnKeyEmergencyCall,  紧急呼叫按钮
    //    } UIReturnKeyType;

    // 设置是否可以拖动
    textView.scrollEnabled = YES;
    // 设置代理
    textView.delegate = self;
    //自适应高度
    textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

心得体会

  1. bounds: 边界
    UIScreen: 屏幕

//主屏幕宽
define kWidth [UIScreen mainScreen].bounds.size.width

//主屏幕高
ine kHeight [UIScreen mainScreen].bounds.size.height

  1. 键盘选择类似紧急拨打之类的选项,实质上还是换行,可能还是要在后面加上相应的。
  2. 设置可以拖动时要保证输入文字超过了初始屏幕的范围,此时需要拖动屏幕。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值