温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

UITextField   编辑框

发布时间:2020-06-18 10:29:28 来源:网络 阅读:365 作者:缘起愿落 栏目:开发技术


  

UITextField 是UIControl的子类,UIControl又是UIView的子类,所以也是一个视图,只不过比UIView多了两个功能:(1)文字显示(2)文本编辑
 

   

创建对象
    UITextField * field = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 220, 30)];


配置属性
    field.backgroundColor = [UIColor whiteColor];
    
  

设置 边框样式


     UITextBorderStyleNone,
     UITextBorderStyleLine,   边框
     UITextBorderStyleBezel,
     UITextBorderStyleRoundedRect 圆角
  

    field.borderStyle = UITextBorderStyleRoundedRect;


设置输入框默显示(提示文字)的文字,但是不做为文本内容的一部分
    field.placeholder = @"请输入用户名";


设置开始显示的文字
    field.text = @"string";


设置文本颜色
    field.textColor = [UIColor redColor];


对齐方式
    field.textAlignment = NSTextAlignmentCenter;


文本字体
    field.font = [UIFont fontWithName:@"Thonburi-Bold" size:20];


是否输入框是否可编辑
    field.enabled = YES;


开始时清空输入框
    field.clearsOnBeginEditing = YES;


是否文字以圆点格式显示 (设置密码模式)
    field.secureTextEntry = YES;


 设置弹出键盘的样式

 field.keyboardType = UIKeyboardTypeNumberPad;
    


键盘右下角的显示的样式
    field.returnKeyType = UIReturnKeyGo;
    

代理
  

代理使用步骤:
       1.设置代理
    
    field.delegate = self;
       2.服从协议
        UITextFieldDelegate
      

    3.实现协议中的方法
          

(BOOL)textFieldShouldReturn:(UITextField *)textField
 


自定义输入视图
    UIView * v1 = [[UIView alloc]initWithFrame:CGRectMake(200, 0, 568, 100)];
    v1.backgroundColor = [UIColor redColor];
   field.inputView = v1;
 


输入视图上方的辅助视图
    field.inputAccessoryView = v1;


3.添加到父视图
    [_View addSubview:field];
 


4.释放所有权
    [field release];
}




向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI