首页 > 学院 > 开发设计 > 正文

UITextField的创建与方法的重写

2019-11-09 14:56:51
字体:
来源:转载
供稿:网友

(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
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表