检测 UITextView 中的行数(iPhone 6 加失败)
Detect number of line in UITextView ( iPhone 6 plus failed)
我使用这个代码:
numOfLine = (textView.contentSize.height - lineHeightFix ) / textView.font.lineHeight;
在 iphone 4,5,5s,6 中,此行运行良好,但在 iPhone 6 中加上它的 return 行号不正确。
我也试过这个代码:
float rows = (textView.contentSize.height - textView.textContainerInset.top - textView.textContainerInset.bottom) / textView.font.lineHeight;
但我会继续处理同样的问题。
我用这段代码解决了这个问题:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect previousRect = CGRectZero;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange: (NSRange)range replacementText:(NSString *)text
{
if (currentRect.origin.y >= previousRect.origin.y)
{
// Counts the lines
}
previousRect = currentRect;
我使用这个代码:
numOfLine = (textView.contentSize.height - lineHeightFix ) / textView.font.lineHeight;
在 iphone 4,5,5s,6 中,此行运行良好,但在 iPhone 6 中加上它的 return 行号不正确。
我也试过这个代码:
float rows = (textView.contentSize.height - textView.textContainerInset.top - textView.textContainerInset.bottom) / textView.font.lineHeight;
但我会继续处理同样的问题。
我用这段代码解决了这个问题:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect previousRect = CGRectZero;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange: (NSRange)range replacementText:(NSString *)text
{
if (currentRect.origin.y >= previousRect.origin.y)
{
// Counts the lines
}
previousRect = currentRect;