此代码绘制了许多文本字段并分配了一个标记,并将标记号写入每个标记。如何在标签号为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++;
}
}
}
答案 0 :(得分:0)
您可以致电viewWithTag
:
UITextField *myField = (UITextField*)[self.view viewWithTag:15];
// Now that I have my field, I can write some text into it:
myField.text = @"X";