UITextField的创建与方法的重写

来源:互联网 发布:vue.js生命周期面试题 编辑:程序博客网 时间:2024/05/01 08:17
  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //初始化textfield并设置位置及大小
    UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];

    //设置输入框的背景颜色
    text.backgroundColor = [UIColor redColor];

    // 中点的x
    CGFloat centerX = self.view.frame.size.width * 0.5;
    CGFloat centerY = self.view.frame.size.height * 0.5;
    text.center = CGPointMake(centerX, centerY);

    // 设置字体
    text.font = [UIFont systemFontOfSize:30];

    text.delegate = self;

    //把textfield添加到视图上
    [self.view addSubview:text];

}

//开始编辑时的方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(@”a”);

//编写时背景颜色修改成绿色textField.backgroundColor = [UIColor greenColor];return YES;

}

  • (void)touchesBegan:(NSSet
0 0
原创粉丝点击