Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone中以编程方式添加标签和文本框_Iphone_Objective C_Ios_Ios4 - Fatal编程技术网

如何在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

如何以编程方式在iphone中添加标签和文本框?
如何设置标签和文本框的边框?

以下代码创建一个
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];