13693

usedRectForTextContainer for NSTextContainer returning improper height

I'm trying to get the size of the rectangle needed to display the text in a given text container with the following code:

s = [manager usedRectForTextContainer:container].size;

I expect the text to be in multiple lines, but it cuts off at the end of a line and doesn't show what is on the next line. This happens only when there are a few extra characters; in a line of about 60 characters, there will be about 10 or 15 leftover that should show on the next line but do not.

Could this be a problem with insets? Perhaps text wrapping? I'm really not sure since I'm new to both iOS and UI programming.

Edit: In the above code, manager is an NSLayoutManager, and container is an NSTextContainer.

I'm pretty sure the the output of this is the issue, because after this function call, if I change the value of s to what I expect it to be, I get the expected layout with the entire string shown.

The information about the Layout Manager is

<NSLayoutManager: 0xd203f60> 1 containers, text backing has 140 characters Currently holding 140 glyphs. Glyph tree contents: 140 characters, 140 glyphs, 1 nodes, 32 node bytes, 384 storage bytes, 416 total bytes, 2.97 bytes per character, 2.97 bytes per glyph Layout tree contents: 140 characters, 140 glyphs, 62 laid glyphs, 2 laid line fragments, 3 nodes, 96 node bytes, 856 storage bytes, 952 total bytes, 6.80 bytes per character, 6.80 bytes per glyph, 31.00 laid glyphs per laid line fragment, 476.00 bytes per laid line fragment

I expect there to be three lines in this case, but it looks like there are only 2 line fragments, meaning perhaps the problem is in my layout manager?

Answer1:

You are creating your own text container, but you also need to configure it. You need to set the lineBreakMode and the numberOfLines that you might want displayed.

In your case I am pret

textContainer.lineFragmentPadding = 0.0 textContainer.lineBreakMode = label.lineBreakMode textContainer.maximumNumberOfLines = label.numberOfLines

Recommend

  • Build Matrix of Comparisons in SQl Server
  • string.IsNullOrEmpty() Doesn't Seem to Work on a String within a Class within a Class
  • Using extern @class in order to add a category?
  • c++ using primitive types as a base class
  • How to open multiple instances of a program in Linux
  • Insertion large number of Entities into SQL Server 2012 [duplicate]
  • to implement a spinner in angular2+
  • C function strchr - How to calculate the position of the character?
  • Wrapping a c#/WPF GUI around c++/cli around native c++
  • Creating NSCollectionView with datasource programatically
  • Where can I find tomesh.c?
  • C# - Most efficient way to iterate through multiple arrays/list
  • Facebook iOS SDK Not Calling Completion Handler
  • netsh acl setting (need alternative method - registry settings?)
  • how do i write assembly code from c#?
  • Memory error in python- how to use more memory
  • Differences in dis-assembled C code of GCC and Borland?
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • Remove final comma from string in vb.net
  • Custom Tabgroup Appcelerator
  • Algorithm for a smudge tool?
  • Change JButton Shape while respecting Look And Feel
  • Display issues when we change from one jquery mobile page to another in firefox
  • Different response to non-authenticated users and AJAX calls
  • Fetching methods from BroadcastReceiver to update UI
  • JavaScriptCore crash on iOS9
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Deserializing XML into class C#
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Symfony2: How to get request parameter
  • jQuery tmpl and DataLink beta
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • GridView Sorting works once only
  • Data Validation Drop Down Box Arrow Disappearing
  • WPF Applying a trigger on binding failure
  • python regex in pyparsing
  • python draw pie shapes with colour filled
  • Checking variable from a different class in C#
  • How to Embed XSL into XML
  • Unable to use reactive element in my shiny app