-(void)loadView
{
[super loadView];
UIView *new= [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
UILabel*lable = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 200, 50)];
lable.layer.cornerRadius = 5;
lable.layer.masksToBounds = YES;
lable.backgroundColor = [UIColor redColor];
lable.text = @"lable";
[self.view addSubview:lable];
UITextField*tf = [[UITextField alloc] initWithFrame:CGRectMake(30, 120, 200, 30)];
tf.backgroundColor = [UIColor greenColor];
tf.placeholder = @"enter here";
tf.text =@"tf";
[self.view addSubview:tf];
tf.delegate = self;
[tf release];
{
[super loadView];
注意这里:一定要先[super loadView];
不然下边对self.view访问会出现死循环.
在这里生成self.view
下边就可以对他进行设置了
UIView *new= [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
UILabel*lable = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 200, 50)];
lable.layer.cornerRadius = 5;
lable.layer.masksToBounds = YES;
lable.backgroundColor = [UIColor redColor];
lable.text = @"lable";
[self.view addSubview:lable];
UITextField*tf = [[UITextField alloc] initWithFrame:CGRectMake(30, 120, 200, 30)];
tf.backgroundColor = [UIColor greenColor];
tf.placeholder = @"enter here";
tf.text =@"tf";
[self.view addSubview:tf];
tf.delegate = self;
[tf release];