Add support to image alignment in ASButtonNode (#2266)

This commit is contained in:
Rocir Santiago
2016-09-19 17:16:49 -07:00
committed by Michael Schneider
parent 3e5b8c3096
commit 5990376f68
2 changed files with 21 additions and 1 deletions

View File

@@ -11,6 +11,16 @@
#import <AsyncDisplayKit/ASTextNode.h>
#import <AsyncDisplayKit/ASImageNode.h>
/**
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.
*

View File

@@ -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;