Search code examples
swiftuitableviewuilabelcelltvos

tvOS: UILabel not resizing when focusing on custom UITableViewCell


I created a view programmatically and added a tableview to it. For that tableview, I created a cell programmatically, but now when I scroll through the cells on the Apple tv, the label does not have the magnifying standard effect and half of the text gets hidden (which half depends if you're going up or down) (see picture).

enter image description here

Does anyone know a solution to this?

Here is also the init for my uitableviewcell:

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    optionLabel = UILabel(frame: CGRectMake(20,20,400,50))
    self.focusStyle = .Default
    addSubview(optionLabel)
}

Solution

  • I just found the problem, when adding to a programmatically created cell, you need to use self.contentView.addSubview instead of just addSubview. This did put my label back on the top.