如何在iPhone中以编程方式添加标签和文本框
如何以编程方式在iphone中添加标签和文本框?如何在iPhone中以编程方式添加标签和文本框,iphone,objective-c,ios,ios4,Iphone,Objective C,Ios,Ios4,如何以编程方式在iphone中添加标签和文本框? 如何设置标签和文本框的边框?以下代码创建一个UILabel和一个UITextField,并将它们添加到视图控制器视图中。将此代码添加到loadView方法中或视图控制器中的某个位置 // Create Label UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 200, 40)]; [myLabel setBackgroundColor:[UIColor cl
如何设置标签和文本框的边框?以下代码创建一个
UILabel
和一个UITextField
,并将它们添加到视图控制器视图中。将此代码添加到loadView
方法中或视图控制器中的某个位置
// Create Label
UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 200, 40)];
[myLabel setBackgroundColor:[UIColor clearColor]];
[myLabel setText:@"Hi Label"];
[[self view] addSubview:myLabel];
[myLabel release];
// Create Text Field
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 200, 40)];
[myTextField setBackgroundColor:[UIColor clearColor]];
[myTextField setText:@"Hi Text Field"];
[[self view] addSubview:myTextField];
[myTextField release];
还可以使用setter方法设置其他属性
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 29, 40)];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:textField];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 29, 40)];
label.text = @"Custom Label";
[label setFont:[UIFont boldSystemFontOfSize:16]];
[self.view addSubview:m_label];