UITableViewCell具有可扩展UIView的动态高度

时间:2016-04-12 12:23:43

标签: ios swift uitableview

由于我想创建具有动态高度的tableview单元格,我不知道在渲染内容后它将采用什么高度。

还有一个隐藏的UIView。当有人点击单元格时,它会呈现,UIView是可见的。

现在问题出现了,当内容越大,其开始隐藏,并且为了使该视图可见,我需要Float中的高度。

// I am using this as a logic for cell expander.
class var expanderHeight : CGFloat { get { return  160 } }
class var defaultHeight :CGFloat { get { return 140 } }

func checkHeight(){
    imageexpander.hidden = (frame.size.height < EaterysTableViewCell.expanderHeight)

}

func watchFrameChanges(){
    if !isObserving {
        addObserver(self, forKeyPath: "frame", options: [NSKeyValueObservingOptions.New, NSKeyValueObservingOptions.Initial], context: nil)
    }
}

func ingnoreFrameChanges(){
    if isObserving {
        removeObserver(self, forKeyPath: "frame")
        isObserving = false
    }
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
    if keyPath == "frame" {
        checkHeight()
    }
}

我有三个这样的标签:

   `|label one|
    |label two|
    |label three|`

如何添加约束,以便label onelabel two的内容在多行(动态)时不会被截断?

0 个答案:

没有答案
相关问题