dhrm
dhrm

Reputation: 14934

How to repaint UIView when text in UILabel changes?

I've a subclass of UIView with a UILabel with is added as subview to the view. In the layoutSubviews method the position and height of the UILabel is calculated. My problem is, that this height should be recalculated, when the text of the UILabel changes. The text is inserted into the label from the UIViewController, so the view does not know when this happen.

Upvotes: 0

Views: 1009

Answers (1)

rob mayoff
rob mayoff

Reputation: 385660

You can subclass UILabel to override setText: like this:

@implementation MyLabel

- (void)setText:(NSString *)text {
    [super setText:text];
    [self.superview setNeedsLayout];
}

Upvotes: 1

Related Questions