我正在尝试对齐单元格的组件,但它不能正常工作。我相信,我只是不明白 ASLayoutSpec 背后的一些简单想法,所以我很感激这里的任何帮助。
我有一个单元格(当然是 ASCellNode),它由 ASTextNode ( asTextLabel
)、ASDisplayNode ( asBackView
,它只是带有圆角的 textLabel 的背景) 和 asImageNode ( asSoundIcon
) 组成。
asBackView
应该比asTextLabel
(它有效)高一点和宽一点,并且asSoundIcon
应该在右侧asBackView
(例如,右侧asBackView
和左侧之间的 4 个点asSoundIcon
),并且它应该垂直居中。
我所拥有的asSoundIcon
是不是垂直居中的,而且它离我想要的更远。
我尝试了很多选项,这只是其中之一,我不明白为什么我的水平间距不起作用,以及如何垂直对齐asSoundIcon
。
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
asSoundIcon.style.preferredSize = CGSize(width: 16, height: 16)
asSoundIcon.style.maxSize = CGSize(width: 16, height: 16)
asSoundIcon.style.minSize = CGSize(width: 16, height: 16)
asBackView.style.minSize = CGSize(width: 30, height: 48)
asTextLabel.style.minSize = CGSize(width: 30, height: 15)
asTextLabel.style.maxWidth = ASDimension(unit: .points, value: screenWidth - 50)
let asBackViewLayout = ASInsetLayoutSpec(insets: UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 24), child: self.asBackView)
let asTextLabelLayout = ASInsetLayoutSpec(insets: UIEdgeInsets(top: 6, left: 12, bottom: 6, right: 36), child: asTextLabel)
let asNewCenterTextLabelLayout = ASCenterLayoutSpec(horizontalPosition: .start, verticalPosition: .center, sizingOption: .minimumWidth, child: asTextLabelLayout)
let asOverlayLayout = ASOverlayLayoutSpec(child: asNewCenterTextLabelLayout, overlay: asBackViewLayout)
let asSoundVerticalLayout = ASRelativeLayoutSpec(horizontalPosition: .start, verticalPosition: .center, sizingOption: .minimumSize, child: asSoundIcon)
let asSoundLayout = ASStackLayoutSpec(direction: .horizontal, spacing: 0.0, justifyContent: .start, alignItems: .start, flexWrap: .noWrap, alignContent: .start, lineSpacing: 0.0, children: [asOverlayLayout, asSoundVerticalLayout])
return asSoundLayout
}