2013-04-24 63 views
0

我在uiview上添加了textview。当我试图输入数据,然后它不显示。文字未显示在uitextview中

继在我的代码

questionView1 = [[UIView alloc]initWithFrame:CGRectMake(30, 40, 260, 350)]; 
[questionView1 setBackgroundColor:[UIColor blackColor]]; 
quesText1 = [[UITextView alloc] initWithFrame:CGRectMake(10, 20, 240, 270)]; 
quesText1.layer.borderWidth = 10.0f; 
[quesText1 setText:@"Everything Ok"]; 
quesText1.layer.borderColor = [[UIColor grayColor] CGColor]; 
quesText1.tag = 100; 
quesText1.delegate = self; 
[questionView1 addSubview:quesText1]; 

其显示默认文本,但tryinng通过键盘输入数据,那么它没有显示。

然而,当我在委托(如下图),然后它的打印正确的值

- (void)textViewDidEndEditing:(UITextView *)textView;{ 
    NSLog(@"%@",textView.text);\\ print correct value but value not showing in  uitextview area. 
} 

DNT知道如何以及为什么它的发生..任何人都知道检查?

+0

我用你的代码,它在我的模拟器中完美地工作。 – yen 2013-04-24 11:59:49

回答

1

一次检查这一项,

UIView* questionView1 = [[UIView alloc]initWithFrame:CGRectMake(30, 40, 260, 350)]; 
    [questionView1 setBackgroundColor:[UIColor blackColor]]; 
    UITextView* quesText1 = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 240, 270)]; 
    quesText1.contentInset = UIEdgeInsetsMake(20.0, 0.0, 20.0, 0.0); 
    quesText1.layer.borderWidth = 10.0f; 
    quesText1.contentMode=UIViewContentModeCenter; 
    [quesText1 setText:@"Everything Ok"]; 
    quesText1.layer.borderColor = [[UIColor grayColor] CGColor]; 
    quesText1.tag = 100; 
    quesText1.delegate = self; 
    [questionView1 addSubview:quesText1]; 
    [self.view addSubview:questionView1]; 
    questionView1.userInteractionEnabled=YES; 

集这行代码中的

quesText1.contentInset = UIEdgeInsetsMake(20.0, 0.0, 20.0, 0.0); 
0

请试试这个...

第一步:

[self.view addSubView:questionView1]; 

第二步:

采用协议'UITextViewDelegate'在.h文件中,并把下面的代码

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text 

{ 

    if ([text isEqualToString:@"\n"]) { 

     [textView resignFirstResponder]; 

    } 
     return YES; 
} 
1

观光尝试

  1. 你的背景颜色为黑色,文本颜色为黑色的 默认.So将文本颜色设置为白色
  2. 问题可能是设置边框,使其覆盖 默认文本
+0

这是我的问题,所以确保在文本之后设置文本颜色。 – Will 2015-10-14 20:16:36