UITextField

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

self.window.rootViewController = [[UIViewController alloc] init];

[_window release];

//UITextField

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

textField.backgroundColor = [UIColor orangeColor];

[self.window addSubview:textField];

[textField release];

/********* 文本控制 *******/

//占位字符串  placehoder

textField.placeholder = @"哈哈哈哈哈哈哼哈";

/******** 输入控制 ********/

// 是否可用 enabled  默认为YES

textField.enabled = YES;

//安全文本输入  secureTextEntry

textField.secureTextEntry = YES;

//键盘样式 keyboardType

//设置键盘样式,比如银行取款密码只需要数字,有的输入邮箱需要@等等

//UIKeyboardTypeAlphabet和UIKeyboardTypeDefault类似,就是我们平时看到那样,都是字母,然后有个按键可以切换符号

//UIKeyboardTypeASCIICapable好像和上面差不多

//UIKeyboardTypeDecimalPad,UIKeyboardTypeNumberPad都是数字,但前者多了一个“小数点”按键

//UIKeyboardTypeEmailAddress-除了字母还有小数点和@出现

//UIKeyboardTypeNamePhonePad-貌似正常

//UIKeyboardTypePhonePad-电话键盘,不仅有数字还有*和#的那种

//UIKeyboardTypeNumbersAndPunctuation-只有数字和标点符号

//UIKeyboardTypeTwitter-除了字母还有@和#,这是微博的符号

//UIKeyboardTypeURL-除字母,还有.com按钮,方便输入

//UIKeyboardTypeWebSearch-主要区别在于return键变成了GO键

textField.keyboardType = UIKeyboardTypeDefault;

//return(回车按键)样式

textField.returnKeyType = UIReturnKeyGoogle;

//开始输入时清空

textField.text = @"输入的内容";

textField.clearsOnBeginEditing = YES;

// 自定义键盘

UIView *textView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

textView.backgroundColor = [UIColor greenColor];

//给输入框指定输入视图为新建的view

//    textField.inputView = textView;

//自定义输入辅助视图

textField.inputAccessoryView = textView;

/******** 外观控制 ********/

//输入框样式

textField.borderStyle = UITextBorderStyleNone;

textField.layer.borderWidth = 1;

//边框颜色

textField.layer.borderColor = [UIColor blueColor].CGColor;

//切圆角(圆形 : 正方形边长的一半)

textField.layer.cornerRadius = 10;

//清楚按钮

textField.clearButtonMode = UITextFieldViewModeAlways;

return YES;

}

你可能感兴趣的:(UITextField)