UITextView

UITextView类继承自UIScrollView,所以它拥有UIScrollView类的属性和方法,支持上下滑动,因此适合长文本的输入。

1.UITextView的属性介绍
UITextView与UITextField的属性大同小异
// 文字内容。
@property(null_resettable, nonatomic, copy) NSString *text;
// UITextView的背景颜色。
@property(nullable, nonatomic, copy) UIColor *backgroundColor UI_APPERANCE_SELECTOR;
// 文字字体颜色。
@property(nullable, nonatomic, strong) UIColor *textColor;
// 文本对齐方式。
@property(nonatomic) NSTextAlignment textAlignment;
// 文本框内边距设置。
@property(nonatomic, assign) UIEdgeInsets textContainerInsets;
// 当文字超过视图的边框时是否允许滑动。
@property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
// 选中文字范围。
@property(nonatomic) NSRange selectedRange;
-(void)viewDidLoad {
    [super viewDidLoad];
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
    
    textView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 200);
    textView.backgroundColor = [UIColor lightGrayColor];
    textView.textAlignment = NSTextAlignmentCenter;
    textView.scrollEnabled = YES;
    textView.textColor = [UIColor redColor];
    textView.keyboardType = UIKwyboardTypwNamePhonePad;
    textView.returnKeyType = UIReturnKeyDone;
    textView.text = @"textView";
    textView.font = [UIFont systemFontOfSize:20.0];
    textView.contentInset = UIEdgeInsetdMake(10.0f, 10.0f, 10.0f, 10.0f,);
    [self.view addSubview:textView];
}

2 UITextView的代理方法

UITextViewDelegate代理协议中如下几个常用的代理是比较常用的,需要优先掌握。
// UITextView对象开始编辑时调用。
-(void)textViewDidBeginEditing:(UITextView *)textView;
// UITextView对象结束编辑时调用。
-(void)textViewDidEndEditing:(UITextView *)textView;
// UITextView的内容和属性变化时调用。
-(void)textViewDidChange:(UITextView *)textView;
// 是否允许开始编辑。当返回值为NO时,UITextView中的内容不能修改。
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView;
// 是否允许结束编辑。当返回值为NO时,UITextView不能结束编辑状态。
-(BOOL)textViewShouldEndEditing:(UITextView *)textView;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值