我有两个标签,一个放在另一个上面。这两个都在 UITableViewCell 中:
我想要一个执行以下操作的语句:
if indexPath.row == 0 || indexPath.row == 1 {
//Remove the bottom label and center the top label vertically in the cell
}
if indexPath.row == 2 || indexPath.row == 3 {
//Keep both labels one on top of the other
}
这些已在 .xib 文件中创建并加载到 TableView 中。我想为此使用自动布局,而且我知道我需要使用一些 socket 才能使其正常工作。关于如何做到这一点有什么想法吗?
最佳答案
func autolayout()
{
if indexPath.row == 0 || indexPath.row == 1 {
//Remove the bottom label and center the top label vertically in the cell
bottomLbl.hidden=true
self.constrainToplbl_top.constant = 20
}
if indexPath.row == 2 || indexPath.row == 3 {
//Keep both labels one on top of the other
self.constrainToplbl_top.constant = 24
self.constrainbottomlbl_top.constant = 2
}
self.layoutIfNeeded()
}
关于ios - 使用自动布局根据条件调整标签位置。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37478223/