您的位置:首页 > 其它

textfield的属性

2015-08-17 08:30 330 查看
#pragma mark -textfield
- (void)_inittextfield
{
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 180, 40)];
    textField.tag = 200;
    //背景颜色
    textField.backgroundColor = [UIColor whiteColor];
    //边框样式
//    textField.borderStyle = UITextBorderStyleRoundedRect;
    //输入的字体的大小
    textField.font = [UIFont boldSystemFontOfSize:16];
    //输入的字体的颜色
    textField.textColor = [UIColor cyanColor];
    //对齐方式
    textField.textAlignment = NSTextAlignmentCenter;
    //首字母自动大写
    textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    //输入框为空时提示的文字
    textField.placeholder = @"请输入内容";
    //开启清除按钮
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    //成为第一响应者
    [textField becomeFirstResponder];
    
    [self.window addSubview:textField];
    
    //create button
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.backgroundColor = [UIColor greenColor];
    button1.frame = CGRectMake(290, 100, 40, 40);
    [button1 setTitle:@"^" forState:UIControlStateNormal];
    //button1 click
    [button1 addTarget:self action:@selector(button1Click) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:button1];
}

- (void)button1Click
{
    UITextField *textField = (UITextField *)[self.window viewWithTag:200];
    [textField resignFirstResponder];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: