我在uiview上添加了一个textview。当我试图输入数据然后它没有显示。
关注我的代码
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];
显示默认文本,但尝试通过键盘输入数据,然后显示。
然而,当我检查其代表(下方)时,它会打印正确的值
- (void)textViewDidEndEditing:(UITextView *)textView;{
NSLog(@"%@",textView.text);\\ print correct value but value not showing in uitextview area.
}
Dnt知道它发生的原因和原因......有谁知道?
答案 0 :(得分: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);
答案 1 :(得分:1)
要尝试的东西
答案 2 :(得分:0)
请试试这个......
步骤1:
[self.view addSubView:questionView1];
步骤2:
在.h文件中采用协议'UITextViewDelegate'
,并输入以下代码
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
}
return YES;
}