I have a problem with my iOS Application. I'm using Swift and XCode 6.3. I have a UITableViewController in my application and in this TableView I've created a prototype cell (Custom). In the design it looks like this:
我的iOS应用程序有问题。我正在使用Swift和XCode 6.3。我的应用程序中有一个UITableViewController,在这个TableView中我创建了一个原型单元格(Custom)。在设计中它看起来像这样:
This is how I want the cells (left the title and on the right a switch in every cell).
这就是我想要的单元格(左边是标题,右边是每个单元格中的一个开关)。
But my problem is, if I run the project it looks like this on my iPhone:
但我的问题是,如果我运行该项目,它在我的iPhone上看起来像这样:
What do I have to do that the cell is looking like my prototype cell? Thank you in advance!
我需要做什么才能让细胞看起来像我的原型细胞?先感谢您!
1 个解决方案
#1
Your title label is probably overlapping the switch view. You need to set an auto-layout constraint of horizontal spacing
between the right edge (trailing in auto layout language...) of the label and the left edge (leading) of the switch view.
您的标题标签可能与开关视图重叠。您需要在标签的右边缘(自动布局语言中的尾部...)和开关视图的左边缘(前导)之间设置水平间距的自动布局约束。
1. ctrl+drag from the label to the switch:
1.按住Ctrl键并从标签拖动到开关:
2. pick horizontal spacing:
2.挑水平间距:
- then change the
relation
to beGreater than or equal
insteadequal
, and set theconstant
to whatever minimum distance you want to have between the label and the switch:
然后将关系更改为大于或等于相等,并将常量设置为标签和开关之间的最小距离:
- add all other missing constrains...
添加所有其他缺少的约束...
EDIT:
To get the label without having to subclass UITableViewCell
you can set a tag to the label:
编辑:要获得标签而不必继承UITableViewCell,您可以为标签设置标签:
Then inside cellForRow..
you can get it with myCell.viewWithTag(999)
然后在cellForRow中..你可以用myCell.viewWithTag(999)得到它
#1
Your title label is probably overlapping the switch view. You need to set an auto-layout constraint of horizontal spacing
between the right edge (trailing in auto layout language...) of the label and the left edge (leading) of the switch view.
您的标题标签可能与开关视图重叠。您需要在标签的右边缘(自动布局语言中的尾部...)和开关视图的左边缘(前导)之间设置水平间距的自动布局约束。
1. ctrl+drag from the label to the switch:
1.按住Ctrl键并从标签拖动到开关:
2. pick horizontal spacing:
2.挑水平间距:
- then change the
relation
to beGreater than or equal
insteadequal
, and set theconstant
to whatever minimum distance you want to have between the label and the switch:
然后将关系更改为大于或等于相等,并将常量设置为标签和开关之间的最小距离:
- add all other missing constrains...
添加所有其他缺少的约束...
EDIT:
To get the label without having to subclass UITableViewCell
you can set a tag to the label:
编辑:要获得标签而不必继承UITableViewCell,您可以为标签设置标签:
Then inside cellForRow..
you can get it with myCell.viewWithTag(999)
然后在cellForRow中..你可以用myCell.viewWithTag(999)得到它