mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-03-28 23:58:50 +08:00
Add support to image alignment in ASButtonNode (#2266)
This commit is contained in:
committed by
Michael Schneider
parent
3e5b8c3096
commit
5990376f68
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user