wolverine
wolverine

Reputation: 309

How can I know upto which part in a NSString a UIlabel can contain?

  1. I have two labels side by side in the ipad with each taking half the screen.
  2. I dont want to use the scrollview.
  3. I just want the left label to contain the exact amount of test it can and want the remaining to go to the right label.

How can I get the length of the string that a fixed size UILabel can contain?

Upvotes: 1

Views: 196

Answers (2)

teradyl
teradyl

Reputation: 2794

Refer to this question with my code on how I solved pretty much the same problem: CTFrameGetVisibleStringRange equivalent for iOS programming?

Upvotes: 0

PfhorSlayer
PfhorSlayer

Reputation: 1366

NSString has a method that can return the size (in pixels) for a string with a given font. You could use this to successively trim off characters until it fits. NSString sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

Upvotes: 2

Related Questions