文章标题

UITextView详解
今天重新看了一下UITextView,发现很多系统方法不懂,于是便有了下面的内容
创建

UITextView * textView = [[UITextView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    /*
     1、设置文本属性:text;
     2、设置文字对齐方式属性:textAlignment;
     3、设置文字颜色属性:textColor;
     4、设置文字字体属性:font;
     5、设置编辑使能属性:editable;
     6、设置背景颜色属性:backgroundColor;
     7、圆角边框:layer.cornerRadius、layer.borderWidth。
     */
    textView.backgroundColor = [UIColor blueColor];
    textView.text = @"aaasddddddddddd";
    textView.font = [UIFont systemFontOfSize:50];
    textView.textAlignment = NSTextAlignmentCenter;
    textView.editable = YES;
    textView.selectable = YES;//里面的内容是否可以交互,例如网址
    /*
     UIDataDetectorTypePhoneNumber     // 手机
     UIDataDetectorTypeLink        // URL
     UIDataDetectorTypeAddress  // 街道地址
     UIDataDetectorTypeCalendarEvent  // 事件
     UIDataDetectorTypeNone          = 0,          
     UIDataDetectorTypeAll
     */
    textView.dataDetectorTypes = UIDataDetectorTypeAll;
    textView.allowsEditingTextAttributes = YES;//允许编辑文本属性
    textView.typingAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:50]}; 
    /*
     UIKeyboardTypeDefault,                    
     UIKeyboardTypeASCIICapable,     ASCII
     UIKeyboardTypeNumbersAndPunctuation,  //数字和符号
     UIKeyboardTypeURL,                    //  URL
     UIKeyboardTypeNumberPad,              // 纯数字
     UIKeyboardTypePhonePad,               //(1-9, *, 0, #, with letters under the numbers).
     UIKeyboardTypeNamePhonePad,           // 数字跟字母
     UIKeyboardTypeEmailAddress,           // email
     UIKeyboardTypeDecimalPad  // 数字跟.
     UIKeyboardTypeTwitter // A type optimized for twitter text entry (easy access to @ #)
     UIKeyboardTypeWebSearch // A default keyboard type with URL-oriented addition (shows space . prominently).
     UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
     */
    textView.keyboardType = UIKeyboardTypeWebSearch;
    /*
     UIReturnKeyDefault,
     UIReturnKeyGo,
     UIReturnKeyGoogle,
     UIReturnKeyJoin,
     UIReturnKeyNext,
     UIReturnKeyRoute,
     UIReturnKeySearch,
     UIReturnKeySend,
     UIReturnKeyYahoo,
     UIReturnKeyDone,
     UIReturnKeyEmergencyCall,
     UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0),
     */
    textView.returnKeyType = UIReturnKeyGo;
    textView.layer.cornerRadius = 10;//圆角
    textView.layer.borderWidth = 3;//边框
    // 7、圆角边框:layer.cornerRadius、layer.borderWidth。
    [self.view addSubview:textView]; 

这里基本所有的系统方法都有了,欢迎补充

这里是代理方法

/*
 1、将要开始编辑:textViewShouldBeginEditing;
 2、将要完成编辑:textViewShouldEndEditing;
 3、开始编辑:textViewDidBeginEditing;
 4、完成编辑:textViewDidEndEditing;
 3、将要改变内容:shouldChangeTextInRange;
 4、内容完成改变:textViewDidChange;
 5、内容被选中:textViewDidChangeSelection。
 */
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{

    return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{

    return YES;
}

- (void)textViewDidBeginEditing:(UITextView *)textView{

    // 3、开始编辑:textViewDidBeginEditing;

}
- (void)textViewDidEndEditing:(UITextView *)textView{

    // 4、完成编辑:textViewDidEndEditing;

}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    // 3、将要改变内容:shouldChangeTextInRange;
    return YES;
}
- (void)textViewDidChange:(UITextView *)textView{

    // 4、内容完成改变:textViewDidChange;

}

- (void)textViewDidChangeSelection:(UITextView *)textView{

    //5、内容被选中:textViewDidChangeSelection。

}

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0){

    return YES;//url

}
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0){

    return YES;//文本副本
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值