I've done quite a lot of work using AsyncDisplayKit until now and I'm really really happy with it. Unfortunately now I've hit a road block.
I can't get a ASButtonNode to have a minimum height (in a ASCellNode if this is important).
class SmallButtonCellNode: ASCellNode {
let normalSmallButton = ASButtonNode()
let selectedSmallButton = ASButtonNode()
init() {
super.init()
self.backgroundColor = UIColor.lightGrayColor()
// .. button title and background configuration here ..
let buttonSizeRange =
ASRelativeSizeRangeMake(
ASRelativeSizeMake(
ASRelativeDimensionMakeWithPercent(0),
ASRelativeDimensionMakeWithPoints(35.0)
),
ASRelativeSizeMake(
ASRelativeDimensionMakeWithPercent(1),
ASRelativeDimensionMakeWithPoints(35.0)
)
);
self.normalSmallButton.preferredFrameSize = CGSize(width: 111.0, height: 35.0)
self.normalSmallButton.flexGrow = true
self.normalSmallButton.sizeRange = buttonSizeRange
self.addSubnode(self.normalSmallButton)
self.selectedSmallButton.preferredFrameSize = CGSize(width: 111.0, height: 35.0)
self.selectedSmallButton.flexGrow = true
self.selectedSmallButton.sizeRange = buttonSizeRange
self.addSubnode(self.selectedSmallButton)
}
// MARK: - Layout
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec {
let spec =
ASStackLayoutSpec(
direction: .Horizontal,
spacing: 20.0,
justifyContent: .SpaceAround,
alignItems: .Center,
children: [self.normalSmallButton, self.selectedSmallButton]
)
return
ASInsetLayoutSpec(
insets: UIEdgeInsets(top: 20.0, left: 20.0, bottom: 20.0, right: 20.0),
child: spec
)
}
}
The result is (although the constrainedSize has a maximum of 100.0 in height):
The ASButtonNodes are only fitting the text height.
I've tried:
- removing the preferred frame size (no effect)
- change from
.Center
to.Stretch
(the button is as tall as the cell - insets) - flexGrow = true in various places
I know that I could change the cell height from 100 to 75 using .Stretch
and then the buttons will automatically end up being 35 pts tall but that's not what I want (because then the layout logic for "The button is 35 pts tall" will actually be part of the collection view delegate ..)
Please help :)