UI 学习 第二章 UItextfield UItextView

UI 学习      第二章        UItextfield         UItextView 

UITextField
1.创建
UITextField *filed = [[ UITextField alloc ] initWithFrame : CGRectMake ( 20 , 30 , 300 , 30 )];
2.设置背景色
filed.backgroundColor = [UIColor redColor];
3.设置边框风格
filed. borderStyle = UITextBorderStyleRoundedRect ;
4.输入提示
filed. placeholder = @" 请输入用户名 " ;
5.开始编辑下一个时这个清零
filed. clearsOnBeginEditing = YES ;
6.右边小清空按钮显示样式
filed. clearButtonMode = UITextFieldViewModeWhileEditing ;
7.密码显示样式
filed. secureTextEntry = YES ;
9.设置返回键样式
filed. returnKeyType = UIReturnKeyGo ;
10.设置左右两边小视图
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 20, 20)];
view.backgroundColor = [UIColor greenColor];
filed.leftView = view;
filed.leftViewMode = UITextFieldViewModeAlways;
11.设置代理
filed. delegate = self ;
以下方法需遵守协议
12.开始编辑时调用
-( void )textFieldDidBeginEditing:( UITextField *)textField{
   
NSLog ( @" 开始编辑 " );
}
13 .判断输入的字符串
-( BOOL )textField:( UITextField *)textField shouldChangeCharactersInRange:( NSRange )range replacementString:( NSString *)string{
   
NSLog ( @" 输入的是 %@" ,string);
   
return YES ;
}
14.当收回键盘时调用:
-( void )textFieldDidEndEditing:( UITextField *)textField{
   
NSLog ( @" 结束编辑 " );
}
15.当点return键时调用
   -( BOOL )textFieldShouldReturn:( UITextField *)textField{
   
NSLog ( @"hi0h00i" );
    [textField
resignFirstResponder ];
   
return YES ;
}
16.点击屏幕空白处收回键盘时调用
-( void )touchesBegan:( NSSet *)touches withEvent:( UIEvent *)event{
   
NSLog ( @" 键盘消失 " );
    [
self . view endEditing : YES ];
}
UITextView
1.创建
UITextView *textView = [[ UITextView alloc ] initWithFrame : CGRectMake ( 20 , 20 , 100 , 100 )];
2.背景色
textView. backgroundColor = [ UIColor grayColor ];
3.是否允许被编辑
textView. editable = YES ;
4.是否允许滚动
textView. scrollEnabled = YES ;
5.弹簧效果
textView. bounces = YES ;
6.边框颜色
textView. layer . borderColor = [ UIColor redColor ]. CGColor ;
7.边框粗细
textView. layer . borderWidth = 1 ;
8.设置圆角,如果想要圆形,则设置为高的一半
textView. layer . cornerRadius = 30 ;
9.设置return键类型
textView. returnKeyType = UIReturnKeyDone ;
方法:
10.判断输入的文本内容(单个)
-( BOOL )textView:( UITextView *)textView shouldChangeTextInRange:( NSRange )range replacementText:( NSString *)text{
   
if ([text isEqualToString : @"\n" ]) {
        [textView
resignFirstResponder ];(当输入的是return时收回键盘)
    }
   
NSLog ( @"uobhohuohno" );
   
return YES ;
}
11.判断文本内的内容(整个)
-( void )textViewDidChange:( UITextView *)textView{
   
NSLog ( @"%@" ,textView. text );
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值