如何在自动布局或swift中自动显示多行内容?

时间:2015-11-27 05:42:31

标签: ios swift autolayout

这是我的代码的一部分:

x8 = int.Parse( txtt10x100t.Text);
                if (x8 > 0)
                {
                    SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=database;Integrated Security=True");
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = cn;
                    cmd.CommandText = "INSERT INTO tbltable " + "(id, name, value , date, iid) " + "VALUES(@id, @name, @value, @date, @iid )";
                    cmd.Parameters.AddWithValue("@id", v2);
                    cmd.Parameters.AddWithValue("@name", "10*100");
                    cmd.Parameters.AddWithValue("@value", x8);
                    cmd.Parameters.AddWithValue("@date", tarikh);
                    cmd.Parameters.AddWithValue("@iid", xxiid);
                    cn.Open();
                    cmd.ExecuteNonQuery();
                    cn.Close();
 x9 = int.Parse(txtt10x150t.Text);
                    if (x9 > 0)
                    {
                        SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=dbdatabase;Integrated Security=True");
                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection = cn;
                        cmd.CommandText = "INSERT INTO tbltable " + "(id, name, value, date, iid) " + "VALUES(@id, @name, @value, @date, @iid )";
                        cmd.Parameters.AddWithValue("@id", v2);
                        cmd.Parameters.AddWithValue("@name", "10*150");
                        cmd.Parameters.AddWithValue("@value", x9);
                        cmd.Parameters.AddWithValue("@date", tarikh);
                        cmd.Parameters.AddWithValue("@iid", xxiid);
                        cn.Open();
                        cmd.ExecuteNonQuery();
                        cn.Close();
x10 = int.Parse(txtt15x100t.Text);
                    if (x10 > 0)
                    {
                        SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=dbdatabase;Integrated Security=True");
                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection = cn;
                        cmd.CommandText = "INSERT INTO tbltable " + "(id, name, value, date, iid) " + "VALUES(@id, @name, @value, @date, @iid )";
                        cmd.Parameters.AddWithValue("@id", v2);
                        cmd.Parameters.AddWithValue("@name", "15*100");
                        cmd.Parameters.AddWithValue("@value", x10);
                        cmd.Parameters.AddWithValue("@date", tarikh);
                        cmd.Parameters.AddWithValue("@iid", xxiid);
                        cn.Open();
                        cmd.ExecuteNonQuery();
                        cn.Close();

// , ete ....

关于其相应的主题板: enter image description here

我已将其设为override func viewDidLoad() { super.viewDidLoad() userName.text = username! let current_status = Status! if current_status == "Online" { Suggestion.text = "He is Online! You can talk with him directly or add him!" } else { Suggestion.text = "He is busy! You'd better talk with him later!" } } ,但当Xcode运行时,其内容仍无法以多行显示。 enter image description here

我该怎么办?

当我添加其宽度和高度限制时,将其水平空间设置为骑行侧,将行号设置为0,它变为: enter image description here

3 个答案:

答案 0 :(得分:0)

固定宽度和灵活高度应该能够满足您的需求。

尝试如下图所示的内容。 enter image description here

如果您要通过代码添加标签文本,则可以在文本中使用\n将其划分为多行。

之类的东西

label.text = "First line\nsecond line"

要添加, 你可以指定label.numberOfLines = 0.这意味着numberOfLines是无穷大

答案 1 :(得分:0)

将从标签到父视图的常量值设置为20的尾随约束。然后,只有标签的内容宽度在父视图中受到限制。

答案 2 :(得分:0)

通过自动布局固定灵活高度