创建UITextField与创建UILabel的步骤很相似。?
1、开辟空间并初始化
2、设置文本显示、输入相关的属性?
3、添加到父视图上,?用以显示?
4、释放
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(50, 180, 280, 40)];
// 占位文本
textField.placeholder = @"哟哟切克闹,煎饼果子来一套";
[self.window addSubview:textField];
[textField release];
属性名 | 描述 | 例子 |
---|---|---|
text | 文本内容 | textField.text = @“abc”; |
textColor | 内容颜色 | textField.textColor = [UIColor redColor]; |
font | 文本字体 | textField.font = [UIFont fontWithName:@“Helvetica- Bold” size:20]; |
placeholder | 占位字符串 | textField.placeholder = @“请输入用户名”; |
textAlignment | 对齐方式 | textField.textAlignment = NSTextAlignmentCenter; |
textField.clearsOnBeginEditing = YES;//清空? textField.clearsOnBeginEditing = NO;//不清空
textField.secureTextEntry = YES;//密码模式? textField.secureTextEntry = NO;//普通模式?片
textField.keyboardType = UIKeyboardTypeNumberPad; //数字键盘
textField.returnKeyType = UIReturnKeyNext;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.clearButtonMode = UITextFieldViewModeAlways; //总是显?示清除按钮
1、创建button对象(如果本类有初始化方法,使用自己的;否则使用父类的)。?
2、设置按钮显示相关的属性?
3、为按钮添加点击事件
?4、添加按钮到父视图上,用以显示?
?5、按钮无需释放(因为使用的是类方法创建的button)
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(35, 220, 20, 20);
[self.window addSubview:button];
[button setTitle:@"确定" forState:UIControlStateNormal];
[button addTarget:self action:@selector(changePic:) forControlEvents:UIControlEventTouchUpInside];
[loginButton setTitle:@“登录” forState:UIControlStateNormal];
NSString *normalTitle = [loginButton titleForState:UIControlStateNormal];
[loginButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
UIColor *normalTitleColor = [loginButton titleColorForState:UIControlStateNormal];
[loginButton setTitleShadowColor:[UIColor redColor] forState:UIControlStateNormal];
UIColor *normalTitleShadowColor = [loginButton titleColorForState:UIControlStateNormal];
[loginButton setBackgroundImage: UIColor *normalTitleColor = [loginButton
[UIImage imageNamed:@“login2.png”] titleColorForState:UIControlStateNormal];
forState:UIControlStateNormal];
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
版权声明:本文为博主原创文章,转载请注明原文地址
原文地址:http://blog.csdn.net/u011752406/article/details/47183361