我正在尝试实现以下布局:
Name: James
Gender: Male
Followers: Brian, Jason and Mike.
我可以想象顶层是使用 CKStackLayout,但是对于每个条目,例如“姓名:詹姆斯”,我怎样才能使名称在框内右对齐?
我正在使用类似以下的内容,将文本包装在固定宽度的组件中并将标签组件设置为使用NSTextAlignmentRight
对齐,但它不起作用,左右都只是“左对齐”:
static CKComponent *singleLine(NSString *left, NSString *right)
{
CKStackLayoutComponent *stackComponent =
[CKStackLayoutComponent
newWithView:{}
size:{}
style:{
.direction = CKStackLayoutDirectionHorizontal,
.alignItems = CKStackLayoutAlignItemsStretch,}
children:{
{.component = [CKStaticLayoutComponent
newWithView:{}
size:{.width = CKRelativeDimension(10)}]},
{.component =
[CKStaticLayoutComponent
newWithView:{}
size:{.width = CKRelativeDimension(88)}
children:{
{
.component =
[CKLabelComponent
newWithLabelAttributes:{
.string = left,
.alignment = NSTextAlignmentRight,
.font = [UIFont boldSystemFontOfSize:14.0],
.maximumNumberOfLines = 1
}
viewAttributes:{}],
}
}],
},
{
.component =
[CKLabelComponent
newWithLabelAttributes:{
.string = right,
.alignment = NSTextAlignmentLeft,
.font = [UIFont systemFontOfSize:14.0],
.maximumNumberOfLines = 1
}
viewAttributes:{}],
.spacingBefore = 10.0
}
}];
return stackComponent;
}
谢谢!