ios - 使用自动布局根据条件调整标签位置。

标签 ios swift

我有两个标签,一个放在另一个上面。这两个都在 UITableViewCell 中:

Label arrangement - one on top of another

我想要一个执行以下操作的语句:

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/

相关文章:

ios - Swift:应用程序因 fatal error 而崩溃:在展开可选值时意外发现 nil?

iphone - 我该如何处理 Flurries 的累积?

ios - 从 Firebase 快照保存/检索数据

iphone - iOS - QuickLook - 如何在没有 UIScrollView 的情况下在 QuickLook 中打开对象

swift - 如何在 TurnBasedGame 中定义配对过程的超时而不需要长时间等待?

json - 从 json 字符串构建 url 时,Alamofire 返回无效的 url

ios - PFQuery findObjectsInBackgroundWithBlock : in WatchKit app works in simulator, 不在 watch 上,除非 iOS 应用程序在前台

javascript - WKWebview stringByEvaluatingJavaScriptFromString 等效?

Xcode 6.0.1、Swift、UIKit、CoreGraphics 缺失

ios - 使用 SwiftyJson 从锁匠那里提取值(value)