Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UITextView计数行未按预期工作_Uitextview_Line_Line Count - Fatal编程技术网

UITextView计数行未按预期工作

UITextView计数行未按预期工作,uitextview,line,line-count,Uitextview,Line,Line Count,我正在尝试获取文本视图中的行数。我在这里搜索了一个解决方案,基本上每个线程都有相同的答案:contentheight/fontlineheight 我有一个有8行的TextView,我运行这个代码,得到contsize:1.944413 NSLog(@"contsize : %f", descLabel.contentSize.height/descLabel.font.lineHeight); 我做错了什么?对于iOS7,这是一个注意在UITextView中可以使用不同字体(和字体大小)的版

我正在尝试获取
文本视图中的行数。我在这里搜索了一个解决方案,基本上每个线程都有相同的答案:contentheight/fontlineheight

我有一个有8行的
TextView
,我运行这个代码,得到
contsize:1.944413

NSLog(@"contsize : %f", descLabel.contentSize.height/descLabel.font.lineHeight);

我做错了什么?

对于iOS7,这是一个注意在UITextView中可以使用不同字体(和字体大小)的版本:

- (NSUInteger)numberOfLinesInTextView:(UITextView *)textView
{
    NSLayoutManager *layoutManager = [textView layoutManager];
    NSUInteger index, numberOfLines;
    NSRange glyphRange = [layoutManager glyphRangeForTextContainer:[textView textContainer]];
    NSRange lineRange;

    for (numberOfLines = 0, index = glyphRange.location; index < glyphRange.length; numberOfLines++){
        (void) [layoutManager lineFragmentRectForGlyphAtIndex:index
                                               effectiveRange:&lineRange];
        index = NSMaxRange(lineRange);
    }
    return numberOfLines;
}
-(NSUInteger)numberOfLinesInTextView:(UITextView*)textView
{
NSLayoutManager*layoutManager=[textView layoutManager];
整数索引,行数;
NSRange glyphRange=[layoutManager glyphRangeForTextContainer:[textView textcainer]];
NSRange-lineRange;
对于(numberOfLines=0,index=glyphRange.location;index