iOS:uilabel多行文本在水平UistackView中被截断

发布于 2025-02-05 08:04:25 字数 869 浏览 3 评论 0原文

问题: 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)

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺渁∝ 2025-02-12 08:04:25

对齐

/* The layout of the arrangedSubviews transverse to the axis;
 e.g., leading/trailing edges in a vertical stack
 */
@property(nonatomic) UIStackViewAlignment alignment;

.fill stackView的

将自动为您生成这些布局属性

 imageView.bottom == label.bottom
 imageView.top == label.top

stackView的大小取决于'语音'image的大小或大小的布局属性imageView是修复的,而不是可调uilable wher即优先级。


对于.center

stackView,通过查看labelimageView之间的最大高度来达到不错的高度。

 _UILayoutSpacer.bottom >= imageView.bottom
 _UILayoutSpacer.bottom >= label.bottom
 _UILayoutSpacer.top <= imageView.top
 _UILayoutSpacer.top <= label.top

alignment

/* The layout of the arrangedSubviews transverse to the axis;
 e.g., leading/trailing edges in a vertical stack
 */
@property(nonatomic) UIStackViewAlignment alignment;

For .fill

StackView will automatically generate these layout attributes for you.

 imageView.bottom == label.bottom
 imageView.top == label.top

the size of stackView depend on the 'voice' image's size or size layout attributes of imageView as it is fixed instead of adjustable UILable which namely have the low priority.


For .center

StackView achieve a decent height by look for the max height between your label and imageView.

 _UILayoutSpacer.bottom >= imageView.bottom
 _UILayoutSpacer.bottom >= label.bottom
 _UILayoutSpacer.top <= imageView.top
 _UILayoutSpacer.top <= label.top
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文