1
我嘗試使用layoutKit構造這個消息氣泡佈局。我正在使用stackLayout來構建它,但它無法呈現時間戳和消息的動態位置。時間戳會在堆棧中水平定位,但如果消息較長,時間戳將在堆棧中垂直定位。
誰能告訴我如何構建這種佈局?
class LayoutSample1: SizeLayout<View> {
init(messageLayout: Layout, timeStampLayout: Layout) {
let stackLayout = StackLayout(
axis: .vertical,
distribution: .fillFlexing,
sublayouts: [messageLayout, timeStampLayout],
config: { view in
view.backgroundColor = UIColor.orange
})
super.init(
sublayout: stackLayout,
config: { view in
view.backgroundColor = UIColor.yellow
})
}
}
class TimestampLayout: LabelLayout<UILabel> {
init(text: String) {
super.init(
text: Text.unattributed(text),
font: UIFont.systemFont(ofSize: 12),
numberOfLines: 0,
alignment: .bottomTrailing,
config: { label in
label.backgroundColor = UIColor.red
})
}
}
class MessageLayout: LabelLayout<UILabel> {
init(text: String) {
super.init(
text: Text.unattributed(text),
font: UIFont.systemFont(ofSize: 14),
numberOfLines: 0,
alignment: .topLeading,
config: { label in
label.backgroundColor = UIColor.red
})
}
}