此代码绘制多个文本字段并分配一个标签并将标签编号写入每个字段。如何在标签号为 15 的文本字段中写一个“X”?
- (void)viewDidLoad
{
int z = 0;
[super viewDidLoad];
for (int y = 10; y < 300; y = y + 25)
{
for (int x = 10; x < 300; x = x + 25)
{
textField = [[UITextField alloc] initWithFrame:CGRectMake(x, y, 25, 25)];
textField.borderStyle = UITextBorderStyleLine;
textField.textColor = [UIColor blackColor];
textField.font = [UIFont fontWithName:@"ArialMT" size:16];
textField.backgroundColor = [UIColor whiteColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.backgroundColor = [UIColor clearColor];
textField.textAlignment = NSTextAlignmentCenter;
textField.enabled = NO;
textField.text = [NSString stringWithFormat:@"%d", z];
[self.view addSubview:textField];
textField.tag = z++;
}
}
}