UITextView if line numbers is 2

<>

This question already has an answer here:

Answers


For Count the number of lines of text

int numLines = textView.contentSize.height / textView.font.lineHeight;
NSLog(@"number of line - %d", numLines);

And for iOS 7 see this Question/Answer.

EDIT for iOS < 7:

This is proper answer

UIFont *myFont = [UIFont boldSystemFontOfSize:13.0]; // your font with size
CGSize size = [textView.text sizeWithFont:myFont  constrainedToSize:textView.frame.size  lineBreakMode:UILineBreakModeWordWrap]; // default mode
int numLines = size.height / myFont.lineHeight;
NSLog(@"number of line - %d", numLines);

For iOS7, a version that take care that you can have differents font (and font size) in your UITextView :

- (NSUInteger)numberOfLines
{
    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;
}

Although you didn't search a lot, here's a way :

CGSize size = [myString sizeWithFont:textView.font constrainedToSize:CGSizeMake(textView.frame.size.width,999) lineBreakMode:UILineBreakModeWordWrap];
int numLines = size.height / textView.font.lineHeight;

Need Your Help

Facebook iOS SDK v 4.1.0 in Swift with Cocoapods: cannot import modules

ios facebook swift cocoapods

I tried to update my Swift project to Facebook SDK v 4.1.0 today (FBSDKCoreKit and FBSDKLoginKit), but it doesn't seem to be working. I cannot import the modules as they are not found.

Which of these is most efficient? ascx vs ashx vs aspx

c# user-controls webpage httphandler

Which of these is most efficient? Assuming they all output the same string.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.