小编Cal*_* Wu的帖子

限制UITextView中的行数

有没有办法"准确"限制UITextView中针对目标iOS 5.0的行数?

我曾经尝试过的

因为我在堆栈溢出搜索.我在之前的链接中发现了这些问题.
在UITextView中,如何获得下一个输入将开始另一行的点
限制UITextview
的行数限制UITextView中的行数

但是UITextView当我试图决定是否返回YES或NO时,我仍然无法获得准确的行数textView:shouldChangeTextInRange:replacementText:.我曾尝试使用代码,它是UITextView限制文本的答案,修改后的代码(在答案中删除-15)如下所示.

- (BOOL)textView:(UITextView *)aTextView shouldChangeTextInRange:(NSRange)aRange replacementText:(NSString*)aText
{
        NSString* newText = [aTextView.text stringByReplacingCharactersInRange:aRange withString:aText];

        // TODO - find out why the size of the string is smaller than the actual width, so that you get extra, wrapped characters unless you take something off
        CGSize tallerSize = CGSizeMake(aTextView.frame.size.width,aTextView.frame.size.height*2); // pretend there's more vertical space to get that extra line to check on
        CGSize newSize = [newText …
Run Code Online (Sandbox Code Playgroud)

objective-c uitextview ios ios5

5
推荐指数
1
解决办法
5935
查看次数

标签 统计

ios ×1

ios5 ×1

objective-c ×1

uitextview ×1