Created
December 19, 2016 15:31
-
-
Save k06a/bcaf413c0e6fb794e53e33ed96a63a09 to your computer and use it in GitHub Desktop.
UIView to replace UILabel with ability to super fast change text color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface LabelMaskedView : UIView | |
@property (strong, nonatomic) UIView *maskView; | |
@property (assign, nonatomic) CGSize cachedIntrisincContentSize; | |
@end | |
@implementation LabelMaskedView | |
- (instancetype)initWitLabel:(UIView *)maskView { | |
self = [super initWithFrame:maskView.frame]; | |
if (self) { | |
maskView.layer.rasterizationScale = [UIScreen mainScreen].scale; | |
maskView.layer.shouldRasterize = YES; | |
_maskView = maskView; | |
self.layer.mask = (id)self.maskView.layer; | |
} | |
return self; | |
} | |
- (CGSize)intrinsicContentSize { | |
return self.maskView.intrinsicContentSize; | |
} | |
- (void)layoutSubviews { | |
[super layoutSubviews]; | |
if (!CGRectEqualToRect(self.maskView.bounds, self.bounds)) { | |
self.maskView.frame = self.bounds; | |
} | |
} | |
- (void)setTextColor:(UIColor *)textColor { | |
[super setBackgroundColor:textColor]; | |
} | |
#pragma mark Forward all unrecognized selectors to mask view | |
- (BOOL)respondsToSelector:(SEL)aSelector { | |
return [super respondsToSelector:aSelector] || [self.maskView respondsToSelector:aSelector]; | |
} | |
- (id)forwardingTargetForSelector:(SEL)aSelector { | |
return self.maskView; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment