Multiline UIButton and autolayout

后端 未结 16 1491
无人共我
无人共我 2020-12-03 13:08

I have created a view controller that looks like this:

\"enter

I want the two

16条回答
  •  遥遥无期
    2020-12-03 13:52

    Lot of answers here, but the simple one by @Yevheniia Zelenska worked fine for me. Simplified Swift 5 version:

    @IBOutlet private weak var button: UIButton! {
        didSet {
            guard let titleHeightAnchor = button.titleLabel?.heightAnchor else { return }
            button.heightAnchor.constraint(equalTo: titleHeightAnchor).isActive = true
        }
    }
    

提交回复
热议问题