我们需要在 iOS 中制作动态视图高度的哪些约束 [英] Which Constraint we need to make dynamic View height in iOS

查看:30
本文介绍了我们需要在 iOS 中制作动态视图高度的哪些约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我是 iOS 新手.所以如果它是重复的或非常基本的问题,请原谅我.

As I am new to iOS. So forgive me if it is duplicate or very basic question.

我正在查看一个视图.下面是大约尺寸.

I am taking one View. Approx below is the size .

x :    5              y :  5
Width  : 590  Height  : 100

我设置了约束

Top to superView  5
Trailing to superView 5
Leading to superView 5

现在我有一个带有动态文本的标签,但文本太大了.

Now I have one Label which have dynamic Text and the Text is too large.

标签约束低于

Top to superView  5
Trailing to superView 5
Leading to superView 5

当我设置视图的背景颜色时,颜色没有设置.如果文本太长.那么如何设置View的Height和背景,让它看起来很清晰.

and when i set the background color of the View the color is not set. If the Text is to Long. So how to set the Height of the View and also set background so that it looks clear.

代码:

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;
        }

如果我给fix Height那么它看起来像这样.

If I give fix Height then it look like this .

输出:

推荐答案

1.为您的视图提供以下约束,高度根据您的需要.这里我给 80.

2.更改高度关系.

3.在上面的 UIview 中添加一个 UILabel,并给出以下约束.

--> 前导、顶部、底部、尾部到 uiview 和高度,即 80.

--> leading, top, bottom, trailing to uiview and height i.e. 80.

4.像使用 UIView 一样设置高度关系.

5.将 UILabel 、 Lines 的属性更改为零

6.现在享受您的限制.

这篇关于我们需要在 iOS 中制作动态视图高度的哪些约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆