因为我是 iOS 的新手。如果这是重复的或非常基本的问题,请原谅我。
我正在接受一个 View 。大约以下是尺寸。
x : 5 y : 5
Width : 590 Height : 100
我给它设置了约束
Top to superView 5
Trailing to superView 5
Leading to superView 5
现在我有一个具有动态文本的标签,但文本太大。
下面是标签约束
Top to superView 5
Trailing to superView 5
Leading to superView 5
当我设置 View 的背景颜色时,颜色未设置。如果文本太长。那么如何设置 View 的 Height 以及设置背景,使其看起来清晰。
代码:
public override void ViewDidLoad()
{
base.ViewDidLoad();
lbl_one.Text = "This is a long label which have long text inside the writing. This is a long label which have long text inside the writing. This is a long label which have long text inside the writing. This is a long label which have long text inside the writing";
lbl_one.LineBreakMode = UILineBreakMode.WordWrap;
lbl_one.Lines = 0;
view_main.BackgroundColor = UIColor.Red;
}
如果我给定高度,那么它看起来像这样。
输出:
最佳答案
<强>1。为您的 View 提供以下限制,高度根据您的需要而定。这里我给 80。
<强>2。更改高度关系。
<强>3。在上面的 UIview 中添加一个 UILabel,并给出以下约束。
--> 前导、顶部、底部、尾部到 uiview 和高度即 80。
<强>4。像使用 UIView 一样设置高度关系。
<强>5。将 UILabel 的属性,行更改为零
6.现在尽情享受你的约束吧。
关于ios - 我们需要在 iOS 中制作动态 View 高度的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41256010/