ComponentKit を使い始めたばかりで、2 つのラベルを水平方向に並べるのに苦労しています。最初のものを左マージンに近づけ、2 つ目を右端に近づけたい。
自動レイアウトでは、次の一連の制約を使用してそれを行うことができます。
H:|-0-[_label1]-[_label2]-0-|
私が試したすべてが機能していないようです。常に同じ結果が得られます。両方のラベルが左揃えです。
これは非常に単純なコンポーネントです:
+ (instancetype)newWithText1:(NSString *)text1 text2:(NSString *)text2
{
return [super
newWithComponent:
[CKStackLayoutComponent
newWithView:{}
size:{}
style:{
.direction = CKStackLayoutDirectionHorizontal,
.alignItems = CKStackLayoutAlignItemsCenter
}
children:{
{
[CKLabelComponent
newWithLabelAttributes:{
.string = text1,
.font = [UIFont systemFontOfSize:20],
.color = [UIColor blackColor]
}
viewAttributes:{
{@selector(setBackgroundColor:), [UIColor clearColor]}
}],
.alignSelf = CKStackLayoutAlignSelfStretch
},
{
[CKLabelComponent
newWithLabelAttributes:{
.string = text2,
.font = [UIFont systemFontOfSize:20],
.color = [UIColor redColor],
.alignment = NSTextAlignmentRight
}
viewAttributes:{
{@selector(setBackgroundColor:), [UIColor clearColor]}
}],
.alignSelf = CKStackLayoutAlignSelfStretch
}
}]];
}
誰かにアドバイスがあれば、大歓迎です。