iOS:uilabel多行文本在水平UistackView中被截断
问题: Uilabel多线文本在水平UistackView中被截断。
我有一个水平的uistackView,在此堆栈视图中,左侧是一个uiimage,右侧是带有一些文本的uilabel。
Uilabel是多行的Uilabel,如果文本很长,则应包装本身。但是,在运行时,它被截断了。
关于如何解决的想法? 我的代码下面:
self.imageView = self.createIconImageView(...)
self.textLabel.text = text
self.textLabel.numberOfLines = 0 // which specify it is multi-line
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.alignment = .fill
stackView.distribution = .fillProportionally
stackView.spacing = 8.0
stackView.addArrangedSubview(self.imageView)
stackView.addArrangedSubview(self.textLabel)
self.containerView.addSubview(stackView)
stackView.edgesToSuperview(insets: Style.containerInsets)
Issue:
UILabel multi-line text get truncated in horizontal UIStackView.
I have a horizontal UIStackView, in this stack view, the left side is an UIImage, right side is a UILabel with some text.
The UILabel is a multiline UILabel, it should wrap itself if text is very long. However, in runtime it got truncated.
Any ideas on how to fix it?
My code below:
self.imageView = self.createIconImageView(...)
self.textLabel.text = text
self.textLabel.numberOfLines = 0 // which specify it is multi-line
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.alignment = .fill
stackView.distribution = .fillProportionally
stackView.spacing = 8.0
stackView.addArrangedSubview(self.imageView)
stackView.addArrangedSubview(self.textLabel)
self.containerView.addSubview(stackView)
stackView.edgesToSuperview(insets: Style.containerInsets)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对齐
.fill
stackView的将自动为您生成这些
布局属性
。stackView的大小取决于'语音'
image
的大小或大小的布局属性imageView
是修复的,而不是可调uilable
wher即优先级。对于
.center
stackView,通过查看
label
和imageView
之间的最大高度来达到不错的高度。alignment
For
.fill
StackView will automatically generate these
layout attributes
for you.the size of stackView depend on the 'voice'
image
's size or size layout attributes ofimageView
as it is fixed instead of adjustableUILable
which namely have the low priority.For
.center
StackView achieve a decent height by look for the max height between your
label
andimageView
.