Multiline UIButton and autolayout

后端 未结 16 1539
无人共我
无人共我 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:57

    A simple solution working for me: make the multiline button to respect its title height in Swift 4.2 by adding a constraint for the button's height based on its title label's height:

    let height = NSLayoutConstraint(item: multilineButton,
                                   attribute: .height,
                                   relatedBy: .equal,
                                   toItem: multilineButton.titleLabel,
                                   attribute: .height,
                                   multiplier: 1,
                                   constant: 0)
    multilineButton.addConstraint(height)
    

提交回复
热议问题