我正在使用 Xcode 4.6.1。我想知道如何在同一个视图控制器上创建各种文本字段,它们之间用一些空格分隔,并以编程方式设置文本。
问问题
22943 次
1 回答
9
没有测试这段代码,但你的问题很简单,快速的谷歌会给你结果。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//first one
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(45, 30, 200, 40)];
tf.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
tf.font = [UIFont fontWithName:@"Helvetica-Bold" size:25];
tf.backgroundColor=[UIColor whiteColor];
tf.text=@"Hello World";
//second one
UITextField *tf1 = [[UITextField alloc] initWithFrame:CGRectMake(45, tf.frame.origin.y+75, 200, 40)];
tf1.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
tf1.font = [UIFont fontWithName:@"Helvetica-Bold" size:25];
tf1.backgroundColor=[UIColor whiteColor];
tf1.text=@"second field";
//and so on adjust your view size according to your needs
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 400, 400)];
[view addSubview:tf];
[view addSubview:tf1];
[self.view addSubview:view];
}
于 2013-03-28T19:30:19.340 回答