Skip to content

Commit

Permalink
Fix a display glitch when directly setting the label text and/or font.
Browse files Browse the repository at this point in the history
Signed-off-by: Zachary Waldowski <zwaldowski@gmail.com>
  • Loading branch information
zwaldowski committed Jan 31, 2012
1 parent 44dde6e commit 86dd233
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions MBProgressHUD.m
Expand Up @@ -44,8 +44,8 @@ @implementation MBProgressHUD
static const CGFloat opacity = 0.9f;
static const CGFloat radius = 10.0f;

static char kLabelTextContext;
static char kDetailLabelTextContext;
static char kLabelContext;
static char kDetailLabelContext;

#pragma mark - Accessors

Expand Down Expand Up @@ -101,9 +101,10 @@ - (void)setProgress:(float)newProgress {
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == &kLabelTextContext || context == &kDetailLabelTextContext) {
if (context == &kLabelContext || context == &kDetailLabelContext) {
dispatch_always_main_queue(^{
[self setNeedsLayout];
[object setNeedsDisplay];
});

return;
Expand All @@ -122,7 +123,10 @@ - (UILabel *)label {
newLabel.textColor = [UIColor whiteColor];
newLabel.numberOfLines = 0;
newLabel.lineBreakMode = UILineBreakModeClip;
[newLabel addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew context:&kLabelTextContext];
[newLabel addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew context:&kLabelContext];
[newLabel addObserver:self forKeyPath:@"font" options:NSKeyValueObservingOptionNew context:&kLabelContext];
[newLabel addObserver:self forKeyPath:@"textColor" options:NSKeyValueObservingOptionNew context:&kLabelContext];
[newLabel addObserver:self forKeyPath:@"textAlignment" options:NSKeyValueObservingOptionNew context:&kLabelContext];
[self addSubview:newLabel];
label = newLabel;
}
Expand All @@ -140,7 +144,10 @@ - (UILabel *)detailLabel {
newLabel.textColor = [UIColor whiteColor];
newLabel.numberOfLines = 0;
newLabel.lineBreakMode = UILineBreakModeClip;
[newLabel addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew context:&kDetailLabelTextContext];
[newLabel addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew context:&kDetailLabelContext];
[newLabel addObserver:self forKeyPath:@"font" options:NSKeyValueObservingOptionNew context:&kDetailLabelContext];
[newLabel addObserver:self forKeyPath:@"textColor" options:NSKeyValueObservingOptionNew context:&kDetailLabelContext];
[newLabel addObserver:self forKeyPath:@"textAlignment" options:NSKeyValueObservingOptionNew context:&kDetailLabelContext];
[self addSubview:newLabel];
detailLabel = newLabel;
}
Expand All @@ -149,18 +156,18 @@ - (UILabel *)detailLabel {

- (void)dealloc {
[label removeObserver:self forKeyPath:@"text"];
[label removeObserver:self forKeyPath:@"font"];
[label removeObserver:self forKeyPath:@"textColor"];
[label removeObserver:self forKeyPath:@"textAlignment"];
[detailLabel removeObserver:self forKeyPath:@"text"];
[detailLabel removeObserver:self forKeyPath:@"font"];
[detailLabel removeObserver:self forKeyPath:@"textColor"];
[detailLabel removeObserver:self forKeyPath:@"textAlignment"];
}

#pragma mark -
#pragma mark Accessor helpers

- (void)updateProgress {
if (![indicator isKindOfClass:[MBRoundProgressView class]])
return;
[(MBRoundProgressView *)indicator setProgress:progress];
}

- (void)updateIndicators {
if (indicator) {
[indicator removeFromSuperview];
Expand Down

0 comments on commit 86dd233

Please sign in to comment.