如何在iPhone中合并两个UITextView?
我在文本视图中的自动完成文本中工作,所以我使用两个 UITextView
第一个 UITextView
(duplicateTextView
) 是背景文本,如水印文本和第二个 UITextView
(customTextView
) 是用户输入文本。当用户在textview中输入多行文本时,customTextView
会自动滚动,但duplicateTextView
不会滚动。那么,如何在输入多行文本时滚动 duplicateTextView
呢?是否可以在 iPhone 中将两个 UITextView
合并在一起?
这里我尝试了源码:
duplicateTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 50, 320, 100)];
duplicateTextView.delegate = self;
duplicateTextView.scrollEnabled = YES;
duplicateTextView.font = [UIFont fontWithName:@"Helvetica" size:14];
duplicateTextView.textColor = [UIColor lightGrayColor];
[self.view addSubview:duplicateTextView];
customTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
customTextView.layer.borderWidth = 2.0;
customTextView.delegate = self;
customTextView.backgroundColor = [UIColor clearColor];
customTextView.layer.borderColor = [UIColor blackColor].CGColor;
customTextView.font = [UIFont fontWithName:@"Helvetica" size:14];
customTextView.textColor = [UIColor blackColor];
[duplicateTextView addSubview:customTextView];
I am worked in autocomplete text in textview, so I am using two UITextView
the first UITextView
(duplicateTextView
) is background text like watermark text and the second UITextView
(customTextView
) is user entering the text. When the user enters multiline text in textview, the customTextView
scrolls automatically but the duplicateTextView
is not scrolling. So, how can I scroll the duplicateTextView
while the multiline text is enters? Is it possible to merge two UITextView
together in iPhone?
Here I tried the source code:
duplicateTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 50, 320, 100)];
duplicateTextView.delegate = self;
duplicateTextView.scrollEnabled = YES;
duplicateTextView.font = [UIFont fontWithName:@"Helvetica" size:14];
duplicateTextView.textColor = [UIColor lightGrayColor];
[self.view addSubview:duplicateTextView];
customTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
customTextView.layer.borderWidth = 2.0;
customTextView.delegate = self;
customTextView.backgroundColor = [UIColor clearColor];
customTextView.layer.borderColor = [UIColor blackColor].CGColor;
customTextView.font = [UIFont fontWithName:@"Helvetica" size:14];
customTextView.textColor = [UIColor blackColor];
[duplicateTextView addSubview:customTextView];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如@KAREEM MAHAMMED 试图解释的那样,您将在发布的最后一行代码中将 customTextView 添加到重复的TextView 中。也许您打算执行以下操作:
[self.view addSubview:customTextView];
也许我误解了你的问题。我在这里添加一些代码,以便您可以看到一个工作示例:
.h 文件:
和 .m 文件:
As @KAREEM MAHAMMED tried to explain, you're adding customTextView to your duplicateTextView in the last line of code you posted. Perhaps you meant to do the following instead:
[self.view addSubview:customTextView];
Perhaps I misunderstood your question. I'm adding some code here so you can see a working example:
.h file:
and the .m file: