diff --git a/AsyncDisplayKit/ASButtonNode.h b/AsyncDisplayKit/ASButtonNode.h index dd619085ce..5049b383b7 100644 --- a/AsyncDisplayKit/ASButtonNode.h +++ b/AsyncDisplayKit/ASButtonNode.h @@ -11,6 +11,16 @@ #import #import +/** + Image alignment defines where the image will be placed relative to the text. + */ +typedef NS_ENUM(NSInteger, ASButtonNodeImageAlignment) { + /** Places the image before the text. */ + ASButtonNodeImageAlignmentBeginning = 0, + /** Places the image after the text. */ + ASButtonNodeImageAlignmentEnd = 1 << 0 +}; + @interface ASButtonNode : ASControlNode @property (nonatomic, readonly) ASTextNode * _Nonnull titleNode; @@ -44,6 +54,11 @@ */ @property (nonatomic, assign) UIEdgeInsets contentEdgeInsets; +/** + * @discusstion Whether the image should be aligned at the beginning or at the end of node. Default is `ASButtonNodeImageAlignmentBeginning`. + */ +@property (nonatomic, assign) ASButtonNodeImageAlignment imageAlignment; + /** * Returns the styled title associated with the specified state. * diff --git a/AsyncDisplayKit/ASButtonNode.mm b/AsyncDisplayKit/ASButtonNode.mm index 64e6ca5a33..1bb7d0235d 100644 --- a/AsyncDisplayKit/ASButtonNode.mm +++ b/AsyncDisplayKit/ASButtonNode.mm @@ -62,6 +62,7 @@ _contentHorizontalAlignment = ASHorizontalAlignmentMiddle; _contentVerticalAlignment = ASVerticalAlignmentCenter; _contentEdgeInsets = UIEdgeInsetsZero; + _imageAlignment = ASButtonNodeImageAlignmentBeginning; self.accessibilityTraits = UIAccessibilityTraitButton; } return self; @@ -480,7 +481,11 @@ } if (_titleNode.attributedText.length > 0) { - [children addObject:_titleNode]; + if (_imageAlignment == ASButtonNodeImageAlignmentBeginning) { + [children addObject:_titleNode]; + } else { + [children insertObject:_titleNode atIndex:0]; + } } stack.children = children;