How can I compute the number of lines of a UILabel with a fixed width and a given text ?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
You can compute the vertical height necessary to display the string using the sizeWithFont:constrainedToSize: method on NSString. Given that size, you can resize the label to display the entire string.
First get the height of the label from the label size using
constrainedSize
once you have the label height then check the number of lines with the font size where
fontsize
is the size you are using for your label. e.g it could be 10 or depending on your requirementsThis code assumes
label
has the desired text and its frame is already set to the desired width.Update:
If all you want is to determine the required height for the label based on its text and current width, then change this to:
The returned
size
is the proper width and height to contain the label.