如何为第一个组件右对齐
How to right align for the first component
我正在尝试实现以下布局:
Name: James
Gender: Male
Followers: Brian, Jason and Mike.
我可以想象顶层是使用CKStackLayout,但是对于每个条目,例如:"Name: James",如何使其在方框内右对齐?
我正在使用类似以下的东西,在固定宽度组件内包装文本,并设置标签组件使用NSTextAlignmentRight
对齐,但它不起作用,左和右都只是'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;
}
谢谢!
我认为你的解决方案很好。另一种解决方案是通过重写computeLayoutThatFits:
来编写自己的自定义布局。一般情况下最好避免这种情况,但对于像表单这样的复杂布局,它可能是一个救星。
也许你应该给外部stacklout(它包裹多个单行,并具有垂直布局方向):.alignItems = CKStackLayoutAlignItemsStretch
相关文章:
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- 如何创建一个QTableWidgetItem,用长文本右对齐,左边有省略号
- 我可以检测和更改 gcc/g++ 中结构的当前数据对齐设置吗?
- 64位机器上的C++内存对齐
- 为什么我可以将变量存储在不是其最小对齐方式的倍数的地址?
- 使 std::vector 分配对齐内存的现代方法
- C++ cout 将双精度对齐到精度 2 并正确对齐
- 在 64 位边界上对齐C++结构数组?
- 使用 g++7 构建的代码在访问未对齐的内存时崩溃
- 整数数据如何以位为单位存储在内存中?不是右对齐吗?
- C++ 如何格式化包含可变整数的文本行,使其在给定宽度内右对齐?
- 右对齐三角形的间距
- 如何使用 cout 将文本右对齐
- 括号对齐样式:在右括号之前中断
- C 输出中的总右对齐
- c++:右对齐的字段输出
- Html文本作为工具提示,向右对齐
- 如何为第一个组件右对齐
- Emacs 右对齐')'
- 第一个带有double的集合是左对齐的,随后的都是右对齐的