Adding constraints to a UIBarButtonItem

后端 未结 2 978
孤独总比滥情好
孤独总比滥情好 2020-12-20 22:17

Xcode is not allowing me to put constraints on my BarButtonItem on a ViewController in the MainStoryBoard. It\'s appearing too far to the left where it\'s unrea

2条回答
  •  [愿得一人]
    2020-12-20 23:16

    Try this:

    let rightConstraint = NSLayoutConstraint(item: your_item_here, attribute: .Right, relatedBy: .Equal, toItem: your_item_here, attribute: .Left, multiplier: 0, constant: 1)
    your_item_here.addConstraint(rightConstraint)
    

    P.S if you want to add constraint to your UIBarButtonItem, it will rise an error

    Value of type 'UIBarButtonItem' has no member 'addConstraint'
    

    P.S.S

    Because of it is not a view class, you can't apply constraints to it.

提交回复
热议问题