Skip to content

Commit 4ed2120

Browse files
committed
Added tintColor convenience methods
tintColor is now forwarded to the underlying view, and much more importantly, the node is notified when the tintColor changes on the view.
1 parent bd30f97 commit 4ed2120

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

AsyncDisplayKit/ASDisplayNode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@
474474
*/
475475
@property (atomic, retain) UIColor *backgroundColor; // default=nil
476476

477+
@property (atomic, retain) UIColor *tintColor; // default=Blue
478+
- (void)tintColorDidChange; // Notifies the node when the tintColor has changed.
479+
477480
/**
478481
* @abstract A flag used to determine how a node lays out its content when its bounds change.
479482
*

AsyncDisplayKit/Details/UIView+ASConvenience.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
@property (nonatomic, getter=isHidden) BOOL hidden;
4949
@property (nonatomic, assign) BOOL autoresizesSubviews;
5050
@property (nonatomic, assign) UIViewAutoresizing autoresizingMask;
51+
@property (nonatomic, retain) UIColor *tintColor;
5152
@property (nonatomic, assign) CGFloat alpha;
5253
@property (nonatomic, assign) CGRect bounds;
5354
@property (nonatomic, assign) UIViewContentMode contentMode;

AsyncDisplayKit/Details/_ASDisplayView.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,11 @@ - (void)asyncdisplaykit_asyncTransactionContainerStateDidChange
213213
[_node asyncdisplaykit_asyncTransactionContainerStateDidChange];
214214
}
215215

216+
- (void)tintColorDidChange
217+
{
218+
[super tintColorDidChange];
219+
220+
[_node tintColorDidChange];
221+
}
222+
216223
@end

AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,25 @@ - (void)setBackgroundColor:(UIColor *)backgroundColor
364364
_setToLayer(backgroundColor, backgroundColor.CGColor);
365365
}
366366

367+
- (UIColor *)tintColor
368+
{
369+
_bridge_prologue;
370+
ASDisplayNodeAssert(!_flags.isLayerBacked, @"Danger: this property is undefined on layer-backed nodes.");
371+
return _getFromViewOnly(tintColor);
372+
}
373+
374+
- (void)setTintColor:(UIColor *)color
375+
{
376+
_bridge_prologue;
377+
ASDisplayNodeAssert(!_flags.isLayerBacked, @"Danger: this property is undefined on layer-backed nodes.");
378+
_setToViewOnly(tintColor, color);
379+
}
380+
381+
- (void)tintColorDidChange
382+
{
383+
// ignore this, allow subclasses to be notified
384+
}
385+
367386
- (CGColorRef)shadowColor
368387
{
369388
_bridge_prologue;

AsyncDisplayKit/Private/_ASPendingState.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ @implementation _ASPendingState
6161
int setAutoresizingMask:1;
6262
int setBounds:1;
6363
int setBackgroundColor:1;
64+
int setTintColor:1;
6465
int setContents:1;
6566
int setHidden:1;
6667
int setAlpha:1;
@@ -109,6 +110,7 @@ @implementation _ASPendingState
109110
@synthesize edgeAntialiasingMask=edgeAntialiasingMask;
110111
@synthesize autoresizesSubviews=autoresizesSubviews;
111112
@synthesize autoresizingMask=autoresizingMask;
113+
@synthesize tintColor=tintColor;
112114
@synthesize alpha=alpha;
113115
@synthesize contentMode=contentMode;
114116
@synthesize anchorPoint=anchorPoint;
@@ -148,6 +150,7 @@ - (id)init
148150
opaque = YES;
149151
bounds = CGRectZero;
150152
backgroundColor = nil;
153+
tintColor = [UIColor colorWithRed:0.0 green:0.478 blue:1.0 alpha:1.0];
151154
contents = nil;
152155
isHidden = NO;
153156
needsDisplayOnBoundsChange = NO;
@@ -265,6 +268,12 @@ - (void)setBackgroundColor:(CGColorRef)color
265268
_flags.setBackgroundColor = YES;
266269
}
267270

271+
- (void)setTintColor:(UIColor *)newTintColor
272+
{
273+
tintColor = newTintColor;
274+
_flags.setTintColor = YES;
275+
}
276+
268277
- (void)setContents:(id)newContents
269278
{
270279
if (contents == newContents) {
@@ -652,6 +661,9 @@ - (void)applyToView:(UIView *)view
652661
if (_flags.setBackgroundColor)
653662
layer.backgroundColor = backgroundColor;
654663

664+
if (_flags.setTintColor)
665+
view.tintColor = self.tintColor;
666+
655667
if (_flags.setOpaque)
656668
view.layer.opaque = opaque;
657669

0 commit comments

Comments
 (0)