• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to set UILabel height to even multiple of line height with auto-layout?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to set UILabel height to even multiple of line height with auto-layout?


  • Subject: How to set UILabel height to even multiple of line height with auto-layout?
  • From: Steve Christensen <email@hidden>
  • Date: Tue, 09 Sep 2014 12:48:16 -0700

I have a UITableViewCell with several stacked UILabels:

- label1: set to 1 line, height = single line height, fixed bottom spacing
- label2: set to 2 lines, height ≥ single line height, fixed bottom spacing
- label3: set to 0 lines, height ≥ single line height, bottom spacing ≥ min spacing

The layout works in the sense that everything lays out based on the constraints, but if label3's text doesn't entirely fit within the allotted space then I want to see it truncated with an ellipsis. Instead label3's height generally is not an even multiple of its line height so any lines that are not entirely visible just don't get drawn.

I tried overriding -layoutSubviews or -updateConstraints in my UITableViewCell subclass, calling super, then figuring that I could set label3.numberOfLines based on the number of lines that evenly fit into the new value of label3.frame.size.height, but after calling super the height hadn't changed from its initial single-line value.

Are these the right places to do this and I'm just missing some extra work or is there a better way?


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Prev by Date: Re: NSOutlineView
  • Next by Date: Re: How to copy Color Panel behaviour?
  • Previous by thread: Re: NSUserDefaults not sticking
  • Next by thread: Re: How to set UILabel height to even multiple of line height with auto-layout?
  • Index(es):
    • Date
    • Thread