According to this answer, I can use intrinsicContentSize
to automatically calculate the width/height. That's what I did, but the result is 0, 0
class AutoSizeUIButton: UIButton{
override func intrinsicContentSize() -> CGSize {
return CGSizeMake(self.frame.size.width, self.titleLabel!.frame.size.height)
}
}
networkButton.setTitle("something-here", forState: .Normal)
networkButton.titleLabel?.font = UIFont(name: "HelveticaNeue", size: 20.0)!
let networkSize = networkButton.intrinsicContentSize()
print("button size", networkSize.width, networkSize.height) //prints 0.0, 0.0
Am I doing something wrong? Note: I don't want to use constraints. I just want to print the width/height.