OS X Cocoa Auto Layout hidden elements

后端 未结 8 1722
被撕碎了的回忆
被撕碎了的回忆 2021-01-31 17:06

I am trying to use the new Auto Layout in Lion because it seems quite nice. But I can not find good information about how to do things. For example:

I have two labels:

8条回答
  •  -上瘾入骨i
    2021-01-31 17:49

    Collapsing UILabel subclass

    One simple solution is to just subclass UILabel and change the intrinsic content size.

    @implementation WBSCollapsingLabel
    
    - (CGSize)intrinsicContentSize
    {
        if (self.isHidden) {
            return CGSizeMake(UIViewNoIntrinsicMetric, 0.0f);
        } else {
            return [super intrinsicContentSize];
        }
    }
    
    - (void)setHidden:(BOOL)hidden
    {
        [super setHidden:hidden];
    
        [self updateConstraintsIfNeeded];
        [self layoutIfNeeded];
    }
    
    @end
    

提交回复
热议问题