Je suis en train de mettre en œuvre la disposition suivante:Comment aligner à droite pour le premier composant
Name: James
Gender: Male
Followers: Brian, Jason and Mike.
Je peux imaginer que le haut niveau est d'utiliser CKStackLayout, mais pour chaque entrée, par exemple "Nom: James", comment puis-je aligner le nom à droite dans une boîte? J'utilisais quelque chose comme ce qui suit, enveloppez le texte dans un composant de largeur fixe et définissez le composant d'étiquette pour utiliser l'alignement NSTextAlignmentRight
, mais cela ne fonctionne pas et les deux gauche et droite ne sont que 'left-align':
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;
}
Merci!
J'ai fini à l'aide » .Size = CKRelativeSizeRange (CKRelativeSize (CKRelativeDimension (88), 0), {}) "dans le' CKStaticLayoutComponent'. Fondamentalement, ajouter une largeur min à 'CKLabelComponent', puis le texte est aligné à l'intérieur de ces limites. – lorixx