您的位置:首页 > 产品设计 > UI/UE

XCODE UITextField 中的属性和用法

2015-05-28 19:26 344 查看
[b]XCODE UITextField 中的属性和用法 一些基本的用法[/b]

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

CGRect frame =CGRectMake(110, 100, 100, 30);

button.frame = frame;

button.backgroundColor = [UIColor purpleColor];

[button setTitle:@"command" forState:UIControlStateNormal];

[button setTitleColor:[UIColor yellowColor ] forState:UIControlStateNormal];

button.layer.cornerRadius = 10.0;

[button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];

[self.window addSubview: button];

UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(110, 150, 100, 30)];

tf.tag = 101;

tf.borderStyle =UITextBorderStyleRoundedRect ;

//UITextBorderStyleLine 输入框框边为黑色的边款,白色背景

//UITextBorderStyleBezel 输入框的边款为灰色,白色背景

//UITextBorderStyleRoundedRect 输入框为圆角,白色背景的输入框

// tf.text =@"abc" ;

tf.textColor = [UIColor purpleColor];

tf.textAlignment = NSTextAlignmentCenter;//输入的内容显示在方框的中心

//提示用户输入什么内容

tf.placeholder =@"用来提示用户";

//与密码输入时一样,输入后显现为黑色的圆点

// tf.secureTextEntry = YES;

//根据输入内容自动调节字体的大小

tf.adjustsFontSizeToFitWidth = YES;

//对用键盘输入内容进行限制和切换

//keyboardType 以下是常用的类型,其他的看单词就知道键盘的类型

//UIKeyboardTypeDecimalPad,UIKeyboardTypeNumberPad 输入框限制为输入数字,且前一个多可以输入小数点

//UIKeyboardTypeNumbersAndPunctuation 键盘为数字加标点符号

//UIKeyboardTypeDefault 为默认(常规)的键盘

tf.keyboardType = UIKeyboardTypeDefault;

//returnKeyType 键盘 显示返回(完成)时执行的操作 提示按钮 以下是常用的几种

//UIReturnKeyEmergencyCall 键盘的右下角 有一个 EmergencyCall 的(紧急呼叫)功能按钮

//UIReturnKeyGoogle 键盘的右下角 有一个 Search (功能提示按钮)

tf.returnKeyType = UIReturnKeyDefault;

//Bool, 输入时清空 输入框的内容

// tf.clearsOnBeginEditing = YES;

//clearButtonMode 输入款清除(一个叉的符号)按钮出显示的时间

// tf.clearButtonMode = UITextFieldViewModeAlways;

//设置代理

// tf.delegate = self;

//自定义设置左视图

// UIView *leftLabel = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];

// leftLabel.backgroundColor = [UIColor yellowColor];

// tf.rightView = leftLabel;

// [leftLabel release];

// tf.rightViewMode = UITextFieldViewModeWhileEditing;

//自定定义键盘

// UIView *leftLabel1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];

// leftLabel1.backgroundColor = [UIColor yellowColor];

// tf.inputView= leftLabel1;

// [leftLabel1 release];

//设置键盘上公用的区域

UIView *leftLabel2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];

leftLabel2.backgroundColor = [UIColor yellowColor];

tf.inputAccessoryView= leftLabel2;

[leftLabel2 release];

//autocapitalizationType 设置对输入的字母大小写的设置

//UITextAutocapitalizationTypeWords 设置每个单词的首字母为大写

//UITextAutocapitalizationTypeSentences 设置一个句子中的首个单词的字母为大写

//UITextAutocapitalizationTypeAllCharacters 每个字母都大写 (7.0)以上的最后一个字母大写

//UITextAutocapitalizationTypeNone 不切换大小写

tf.autocapitalizationType = UITextAutocapitalizationTypeNone;

[self.window addSubview:tf];//2

[tf release];

[self.window makeKeyAndVisible];

return YES;

}

-(void)test

{

UITextField *tf =(UITextField *) [self.window viewWithTag:101];

//将键盘移除

[tf resignFirstResponder];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: