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

2014-09-10 Thread Steve Christensen
That's not the issue I'm having.

Let's say, for example, that label3 contains abcdefghijklmnopqrstuvwxyz; the 
line height for the font 10; and when the label is laid out the label height is 
25. This results in a label that looks like this:

+——+
|abcdefghij|
|klmnopqrst|
|(blank)   |
+——+

The first two lines are visible, but the third line is not drawn because the 
label is not tall enough to completely draw the last line.

My question, below, was trying to determine how I could adjust the label height 
so that it's an even multiple of the font's line height, so in this case the 
label height would be adjusted to 20 (2 x 10) and the text would be drawn like 
this:

+——+
|abcdefghij|
|klmnopqrs…|
+——+


On Sep 9, 2014, at 5:45 PM, Cosmo dennisbi...@gmail.com wrote:

 In my experience, setting a label's numberOfLines property to 1 and its 
 lineBrakeMode property to NSLineBreakByTruncatingTail is all it takes to get 
 text to truncate. You can do it in code, or in IB if you’re laying out your 
 tableViewCell in a storyboard or XIB.
 
 On Sep 9, 2014, at 12:48 PM, Steve Christensen puns...@mac.com wrote:
 
 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-09-09 Thread Steve Christensen
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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com