2012-11-04 29 views
0

我創建了一個生成例如文本字段的生成器。無法在UIview上顯示UITextview

-(UITextField *)generateTextField 
{ 
    UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(100, 150, 100, 40)]; 
    textfield.layer.borderColor = [[UIColor colorWithRed:171.0/255.0 green:171.0/255.0 blue:171.0/255.0 alpha:1.0] CGColor]; 

    return textfield; 
} 

現在,我在用UIView調用另一個類的這個函數。但它不顯示我在屏幕上的文本框:

- (void)viewDidLoad 
{ 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    SubtaskGenerator *scg = [[SubtaskGenerator alloc]init]; 
    UITextField * textfield = [scg generateTextField]; 

    [self.view addSubview:textfield]; 
} 

我是否必須以另一種方式進行操作?

回答

0

它確實存在,但你看不到它。 默認的UITextField邊框寬度爲0.0,所以你不會看到它或它所構成的文本字段。 只需將此行添加到generateTextField函數:

textfield.layer.borderWidth = 2.0;